Ping ip address

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

Hi all

I want to ping an ipaddress/host to check for a response.

Is there any easy way in C#/.Net to do this?

Thanks
Kev
 
You could perform a request and check whether you get anything back.
public static bool Ping ( string url )
{
WebRequest r = WebRequest.Create(url);
try
{
r.GetResponse();
return true;
}
catch
{
}
return false;
}
 
Hi Dennis

That appeared promising but fails with the the message "Access to the path
is denied", I'm trying to check if another pc on the network is available,
basically checking the \\pcname\c$ share.

I do have access to the machine as I can browse to the shaire, however,
WebRequest failes with that exception message.

Any ideas?
 
Mantorok,

Why not just try and open the share up? You can check for the existence
through the Exists methods on the DirectoryInfo and Directory classes.

And if you get an access denied error, then it means that you shouldn't
be trying to get to that share in the first place.

The first task would be to see if you have access to the path you want
to access. If you don't, then everything else is moot.
 
Nicholas

I would use the Directory.Exists but it takes around 2 mins if the pc is not
connected, which is unacceptable.

The access-denied error is also incorrect, as I do have access to it.

Kev

Nicholas Paldino said:
Mantorok,

Why not just try and open the share up? You can check for the existence
through the Exists methods on the DirectoryInfo and Directory classes.

And if you get an access denied error, then it means that you shouldn't
be trying to get to that share in the first place.

The first task would be to see if you have access to the path you want
to access. If you don't, then everything else is moot.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Mantorok said:
Hi Dennis

That appeared promising but fails with the the message "Access to the path
is denied", I'm trying to check if another pc on the network is
available,
basically checking the \\pcname\c$ share.

I do have access to the machine as I can browse to the shaire, however,
WebRequest failes with that exception message.

Any ideas?
 
Mantorok,

If you want to ping the machine, then I would actually try to ping the
machine then. You should be able to resolve the IP, and then just ping
normally (like you would any other network host). You can use the libraries
at the indy project to do this.

However, this assumes that the machines are servicing ping requests.

As for having access, you might have access to certain things on the
machine, but whatever it is on that machine you want to access, you don't
have access to (assuming that you can reach the machine).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mantorok said:
Nicholas

I would use the Directory.Exists but it takes around 2 mins if the pc is
not
connected, which is unacceptable.

The access-denied error is also incorrect, as I do have access to it.

Kev

in
message news:[email protected]...
Mantorok,

Why not just try and open the share up? You can check for the existence
through the Exists methods on the DirectoryInfo and Directory classes.

And if you get an access denied error, then it means that you shouldn't
be trying to get to that share in the first place.

The first task would be to see if you have access to the path you
want
to access. If you don't, then everything else is moot.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Mantorok said:
Hi Dennis

That appeared promising but fails with the the message "Access to the path
is denied", I'm trying to check if another pc on the network is
available,
basically checking the \\pcname\c$ share.

I do have access to the machine as I can browse to the shaire, however,
WebRequest failes with that exception message.

Any ideas?

You could perform a request and check whether you get anything back.
public static bool Ping ( string url )
{
WebRequest r = WebRequest.Create(url);
try
{
r.GetResponse();
return true;
}
catch
{
}
return false;
}

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Hi all

I want to ping an ipaddress/host to check for a response.

Is there any easy way in C#/.Net to do this?

Thanks
Kev
 
Hi Kev,

It isn't at all clear what you mean by "check to see if the machine is
available." Available for what?
I'm guessing that you just want to make sure that the machine responds on
the network, so that you can do another task, like open the directory,
without the fear of it taking a long time if that machine is not actually
available.

In that case, and assuming that the other machine is set to respond to a
ICMP request, there is nothing wrong with using Ping.

There are a large number of third party libraries available that implement
the ICMP protocol. In the past, I've been happy with products from Mabry,
and they have a ping control for about $100.

Or, you could roll your own (although probably not in less than a few hours
(?), depending on how much your time is worth).

--- Nick
 
The idea is to ping the machine programmtically, there may be 10-15 laptops
that I need to check are on the network.

I have adminstrator rights to all of these machines, so there is nothing I
can't do on them, all I want to do here is merely check for their existence
on the network.

Kev

Nicholas Paldino said:
Mantorok,

If you want to ping the machine, then I would actually try to ping the
machine then. You should be able to resolve the IP, and then just ping
normally (like you would any other network host). You can use the libraries
at the indy project to do this.

However, this assumes that the machines are servicing ping requests.

As for having access, you might have access to certain things on the
machine, but whatever it is on that machine you want to access, you don't
have access to (assuming that you can reach the machine).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mantorok said:
Nicholas

I would use the Directory.Exists but it takes around 2 mins if the pc is
not
connected, which is unacceptable.

The access-denied error is also incorrect, as I do have access to it.

Kev

in
message news:[email protected]...
Mantorok,

Why not just try and open the share up? You can check for the existence
through the Exists methods on the DirectoryInfo and Directory classes.

And if you get an access denied error, then it means that you shouldn't
be trying to get to that share in the first place.

The first task would be to see if you have access to the path you
want
to access. If you don't, then everything else is moot.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Hi Dennis

That appeared promising but fails with the the message "Access to the path
is denied", I'm trying to check if another pc on the network is
available,
basically checking the \\pcname\c$ share.

I do have access to the machine as I can browse to the shaire, however,
WebRequest failes with that exception message.

Any ideas?

You could perform a request and check whether you get anything back.
public static bool Ping ( string url )
{
WebRequest r = WebRequest.Create(url);
try
{
r.GetResponse();
return true;
}
catch
{
}
return false;
}

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Hi all

I want to ping an ipaddress/host to check for a response.

Is there any easy way in C#/.Net to do this?

Thanks
Kev
 
Back
Top