• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Getting all the computers in a network using "net view".  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am not sure if this is the right forum to post this query. However, I really need some expert guidance.
I had done little research for: How to find out the name of the computers that are connected in your network. I was successful in solving this issue. I was able to find those names using :
Process process = Runtime.getRuntime().exec("net view");
After running this command, I use the getInputStream() to extract those name and then I display them.
This works fine on the Windows 2000 Pro. machine. However, when I try to run the same thing on Windows 98, the system seems to hang. I think thats because the output of process.exitValue() is not equal to 0. Is there a different command that I should run for different OS?
I mean is there a different way to launch "net view" command in Windows 98 than in Windows 2000 Pro using Runtime?
I am really confused. Please help.
For everyone's reference, the code that I use is as follows:
StringBuffer strBuffer= new StringBuffer();
String line= null;
try
{
Process process = Runtime.getRuntime().exec("net view");
BufferedReader b = new BufferedReader(new
InputStreamReader(process.getInputStream()));
PrintWriter to= new PrintWriter(process.getOutputStream());
to.close();
try
{
// we need the process to end, else we'll get an
// illegal Thread State Exception
line= b.readLine();
while (line != null)
{
strBuffer.append(line+"\n");
line= b.readLine();
}
process.waitFor();
}
catch (InterruptedException inte)
{
System.out.println("InterruptedException Caught");
}
if (process.exitValue() == 0)
{
System.out.println(strBuffer.toString());
}
process.destroy();
}catch (IOException ioe)
{
System.out.println( "IO Exception Occured While Messing aruond with Processes! -> " + ioe);
}
Thanks,
Riddhi.
 
Bartender
Posts: 9559
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Riddhi Shah:

I mean is there a different way to launch "net view" command in Windows 98 than in Windows 2000 Pro using Runtime?


Have you tried running the "net view" on a win98 command line? I don't have a win98 machine handy to check it.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Joe is on the right track here. Windows 98 doesn't support most of the net commands. Basically if you are going to use the net command to enumerate machines on the network, they will all have to be NT kernel machines (NT, 2K or XP).
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the last answer is true.
w98 isn't meant to be a networking os.
On Linux your command will fail of course too.
Perhaps there you could be successful with

-b: broadcast
-c1: requestcount = 1
or whatever the network-adress is.
But you get the problem that only root might be allowed to ping.
I don't know, wheter there is a standard-network-command to get every host (online| known).
 
Riddhi Shah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry in taking time to get back to you all.
I tried using the "net view" command from the command prompt of Windows 98 machine and it gives me all the names of the machines connected to the network.
I really dont understand where I am going wrong.
Please help.
Thanks,
Riddhi.
 
Joe Ess
Bartender
Posts: 9559
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Riddhi Shah:

I tried using the "net view" command from the command prompt of Windows 98 machine and it gives me all the names of the machines connected to the network.


I'm really surprized that it worked. In your first post, you state that process.exitValue() is not equal to 0, but you also say that the program hangs. Either the process is exiting or hanging. Which is it?
I'm suspicious that the readLine method is blocking rather than returning null so your program never detects that the process has ended. I would first replace your string buffer in your loop with a simple System.out.println to see if the process is executing. If you don't get output, your problem is with the "net view" command and we can't do much about that. If you do get output and the program hangs, your problem is elsewhere (i.e. readLine()). To remedy this I think you will have to create a thread to read the output from the spawned process while you wait on process.waitFor() in your main execution thread. That's just common sense when working with asynchronous processes.
 
Riddhi Shah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish I had that much of common sense.
You are right. I used the thread and it worked. There was nothing wrong with the"net view" command.
Thanks for all the inputs.
 
Joe Ess
Bartender
Posts: 9559
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Riddhi Shah:
I wish I had that much of common sense.


You do now. Congrads on a lesson learned and problem solved.
 
Riddhi Shah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!