Searching network computers

bri189a

Senior Contributor
Joined
Sep 11, 2003
Messages
1,004
Location
VA
Don't try to make sense of this (the why), there is a purpose to it (I need the how).... I know .NET supports UNC paths for savings, deleting, blah blah, but the problem is you have to know both the computer name (or IP) and shared folder. Not a problem 99% of the time. The particular application I'm making though is suppose to go through the network and get all the computers within an IP range which I've done below:

C#:
//(string) ipaddress holds an ip-address is standard number
//format.  I use a search range (ex: 169.0.0.1 - 169.0.0.255) 
//prior to this code snippet in a loop incrementing the last octet

IPHostEntry hostInfo = Dns.Resolve(ipaddress);
Console.WriteLine("Computer: " + hostInfo.HostName);

Later, once I figure out the next piece of the puzzle rather than simply displaying the computer name I will be using it to search for shared folders, all of this information will go into a database for later use.

As you may or may not know you can't use the GetDirectories function because you will get an error (UNC paths must be in the format of //servername/share) - so I've been beating my brain out on this all day and I'm burnt; any ideas? Am I doing this the hard way for resolving IP address to common name? I've gone from really trying to find an answer exactly to randomly picking help files that are remotely close, all to no avail, so now that I've gotton to the I give up point... here I be....

Thanks,
Brian
 
I figured out what I was trying to do; I'll post it when I have it complete so others may learn.
 
One possibility could be something like that:
Visual Basic:
For i = 0 to 255
   For j = 0 to 255
      sIP = "192.168." + i.tostring + "." + j.tostring
      IPHostEntry hostInfo = Dns.Resolve(sIP);
      Console.WriteLine("Computer: " + hostInfo.HostName);
   Next j
next i
I know, this method is more than nonperformant, but it's the only way I know of scanning an address range using .net. You will also need some errorhandling.

Perfomance increases rapidly with smaller address-ranges.

Any better idea better than that is appreciated!

Voca
 
Back
Top