I’m trying to ping a server based on an IP Address and a port, using the Ping class,
I have to convert the IP Address to an array of bytes, how am I doing it?
I took this method from somewhere
bool IsConnectedToInternet
{
get
{
Uri url = new Uri("www.abhisheksur.com");
string pingurl = string.Format("{0}", url.Host);
string host = pingurl;
bool result = false;
Ping p = new Ping();
try
{
PingReply reply = p.Send(host, 3000);
if (reply.Status == IPStatus.Success)
return true;
}
catch { }
return result;
}
}
I just have to ping the server based on an IP, not a URL.
Thank you.
Use the IPAddress class and Ping.Send(IPAddress address) method. If you’re trying to convert from IPAddress to bytes, it offers handy hosttonetwork and networktohost methods.
http://msdn.microsoft.com/en-us/library/system.net.ipaddress.aspx
http://msdn.microsoft.com/en-us/library/hb7xxkfx.aspx