Searching network computers

bri189a

Well-known member
Joined
Sep 11, 2003
Messages
1,004
Location
VA
Dont 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 Im making though is suppose to go through the network and get all the computers within an IP range which Ive 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 cant use the GetDirectories function because you will get an error (UNC paths must be in the format of //servername/share) - so Ive been beating my brain out on this all day and Im burnt; any ideas? Am I doing this the hard way for resolving IP address to common name? Ive 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 Ive gotton to the I give up point... here I be....

Thanks,
Brian
 
Still would love to have some help on this if any of you have any ideas...
 
I figured out what I was trying to do; Ill post it when I have it complete so others may learn.
 
One possibility could be something like that:
[VB]
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
[/VB]
I know, this method is more than nonperformant, but its 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
 

Similar threads

M
Replies
0
Views
145
MyCatAlex
M
P
Replies
0
Views
176
Policy standard local admin account with Active Di
P
Back
Top