found out if a remote computer is on the intranet network ?

  • Thread starter Thread starter Franck
  • Start date Start date
F

Franck

hello ,
I use the following method to find out if a remote computer in an
intranet is connected or not on the intranet network...

but the following is very long at least 10-11s per host

are there any other know methods

thank for your help
Franck

using System.Net;
public static void pinger(string hostname,ref bool found)
{
try
{
Dns.GetHostByName(hostname);
}
catch(System.Net.Sockets.SocketException )
{
found=false;
}
catch(System.Security.SecurityException )
{
found=true;
}
catch(Exception excep)
{
found=false;
}
found=true;
}
 
Hi Franck,

you may try the following to see if it is faster:

using System.Management;



string Ping(string address) {

ManagementObjectSearcher searcher =

new ManagementObjectSearcher("root\\CimV2", "Select * From
Win32_PingStatus where Address = '" + address + "'");

ManagementObjectCollection objects = searcher.Get();

if (objects != null) {

foreach (ManagementObject mo in objects) {

object statusCode = mo["StatusCode"];

if ((statusCode != null) && ((uint) statusCode == 0)) {

return (string) mo["ProtocolAddress"];

}

}

}

return null;

}


This method will either return the ip address of the host specified in the
address parameter (host name orip address) or null, if the ping did not
succeed.

Michael
 
Thanks for your
help but it is lasting the same....
Hi Franck,

you may try the following to see if it is faster:

using System.Management;



string Ping(string address) {

ManagementObjectSearcher searcher =

new ManagementObjectSearcher("root\\CimV2", "Select * From
Win32_PingStatus where Address = '" + address + "'");

ManagementObjectCollection objects = searcher.Get();

if (objects != null) {

foreach (ManagementObject mo in objects) {

object statusCode = mo["StatusCode"];

if ((statusCode != null) && ((uint) statusCode == 0)) {

return (string) mo["ProtocolAddress"];

}

}

}

return null;

}


This method will either return the ip address of the host specified in the
address parameter (host name orip address) or null, if the ping did not
succeed.

Michael

hello ,
I use the following method to find out if a remote computer in an intranet
is connected or not on the intranet network...

but the following is very long at least 10-11s per host

are there any other know methods

thank for your help
Franck

using System.Net;
public static void pinger(string hostname,ref bool found)
{
try
{
Dns.GetHostByName(hostname);
}
catch(System.Net.Sockets.SocketException )
{
found=false;
}
catch(System.Security.SecurityException )
{
found=true;
}
catch(Exception excep)
{
found=false;
}
found=true;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top