IP ping

  • Thread starter Thread starter *FeDe*
  • Start date Start date
F

*FeDe*

What of the framework can I use to know if a computer IP is avaible on my
net?
I was thinking about a ping service, is it avaible in the framework?
Thanks
 
Hello *FeDe*,

There is no API for this. You can use Sockets and ICMP or WMI Win32_PingStatus
(not 100% sure about this)

There are some samples for ICMP and Sockets
http://www.christopherlewis.com/Ping.cs.htm
http://www.mentalis.org/soft/class.qpx?id=4


*> What of the framework can I use to know if a computer IP is avaible
*> on my
*> net?
*> I was thinking about a ping service, is it avaible in the framework?
*> Thanks
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangel
 
*FeDe* said:
What of the framework can I use to know if a computer IP is avaible on my
net?
I was thinking about a ping service, is it avaible in the framework?
Thanks
If you are using Microsoft.NET 2.0 you can:

using System.Net.NetworkInformation;

PingReply reply = ping.Send("Hostname");

if (reply.Status != IPSatatus.Success)
{
Console.WriteLine("Ping Status is {0}", reply.Status);
}
 
From MSDN

static void Main(string[] args)
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();

// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;

// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
//PingReply reply = pingSender.Send(args[0], timeout,
buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Address: {0}",
reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}",
reply.RoundtripTime);
Console.WriteLine("Time to live: {0}",
reply.Options.Ttl);
Console.WriteLine("Don't fragment: {0}",
reply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}",
reply.Buffer.Length);
}

Console.ReadLine();
}

Working good for me.

Also you may like to check

http://www.codeproject.com/dotnet/CSharpPing.asp

Thanks
-Cnu.
 
Back
Top