Ping / online check

  • Thread starter Thread starter JME-56
  • Start date Start date
J

JME-56

Is there a class in the .NET framwork that can allow me to ping a pc?
I only need to know if there is received an answer, so i can know the
computer is online.
it is for a small tool that will allow me to see what computers in the
network are online.

Thanks,
Sijmen Mulder
 
You can use something like this and parse the output


public void OnPing(object sender, System.EventArgs e)
{
ProcessStartInfo PSI= new ProcessStartInfo("ping",TextBox1.Text);
PSI.UseShellExecute=false;
PSI.RedirectStandardOutput=true;
PSI.RedirectStandardInput=true;

if (p==null)
{
p = Process.Start(PSI);
}
else
{
p.StandardInput.Write(TextBox2.Text);
}

string output = p.StandardOutput.ReadToEnd();
if (p.HasExited)
{
p.WaitForExit();
}
Label1.Text= output;
}

--
Moreno Tonin
e-mail: (e-mail address removed)
cell.: +393289026549
uff.: +39031525082
p. website: www.moredev.com

Datain srl
Microsoft Certified Partner
Telecom Business Service Provider
Progress Software Partner
via Lenticchia 16 22100 Como CO
www.datain.it ; www.datain.biz
 
Thank you for your very quick reply.
But i don't understand what the if structure is for:

if (p==null)
{
p = Process.Start(PSI);
}
else
{
p.StandardInput.Write(TextBox2.Text);
}

What is P? And what does the above code do?

And is there maybe a way just to check if there is a reply?
 
If I remember right, there is a port (7 I think) that is always used for
echo or bounce-back. So if you were to 'connect' to it, then the computer
is online. Anyone? Am I correct?

Basically, that is all you really need right? Your not sending special
information or such, you just want to know if its 'online'
 
Back
Top