473,378 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Ping ip address

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
Nov 16 '05 #1
9 15276
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
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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

Nov 16 '05 #2
http://www.google.co.uk/search?q=ping+c%23 if none of them are anygood,
i can give you one I've got chris at sloppycode . net

Nov 16 '05 #3
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?

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:n5********************@news4.e.nsc.no...
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
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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


Nov 16 '05 #4
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]
- mv*@spam.guard.caspershouse.com
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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?

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:n5********************@news4.e.nsc.no...
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
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
> 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
>
>



Nov 16 '05 #5
I was hoping it could be done using the Credentials property:
r.Credentials = new System.Net.NetworkCredential
("username", "password", "domain");
but unfortunately, it does not seem to be enough.

You might want to have a look at:
http://www.netomatix.com/ImpersonateUser.aspx
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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?

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:n5********************@news4.e.nsc.no...
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
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
> 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
>
>



Nov 16 '05 #6
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uN**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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?

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:n5********************@news4.e.nsc.no...
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
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
> 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
>
>



Nov 16 '05 #7
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]
- mv*@spam.guard.caspershouse.com

"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uN**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
> 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?
>
> "Dennis Myrén" <de****@oslokb.no> wrote in message
> news:n5********************@news4.e.nsc.no...
>> 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
>> "Mantorok" <no**@tiscali.co.uk> wrote in message
>> news:cn**********@newsfeed.th.ifl.net...
>> > 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
>> >
>> >
>>
>>
>
>



Nov 16 '05 #8
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

"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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?

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:n5********************@news4.e.nsc.no...
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
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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



Nov 16 '05 #9
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ej**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uN**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:cn**********@newsfeed.th.ifl.net...
> 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?
>
> "Dennis Myrén" <de****@oslokb.no> wrote in message
> news:n5********************@news4.e.nsc.no...
>> 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
>> "Mantorok" <no**@tiscali.co.uk> wrote in message
>> news:cn**********@newsfeed.th.ifl.net...
>> > 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
>> >
>> >
>>
>>
>
>



Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: techprot-google04 | last post by:
I've found tons of sample code on pinging - but all start with the host name, resolve the ip address and do the ping. Does anyone have any sample code that does a ping from an ip address alone?...
0
by: Ed | last post by:
I've attached some VB.NET code I've hacked together (some taken from MS examples & newsgroup postings) that will perform a ping or IcmpSendEcho using the icmp.dll (see this for more info:...
2
by: Ryan | last post by:
I want to ping every IP on a subnet (255 IP's) and display in a table what IP's are active. I'm currently using a For loop but this takes forever because it pauses to test each Ping. So my guess...
5
by: Deepak | last post by:
I am programing a ping application which pings various centers . I used timer loop and it pings one by one. Now when i finish pinging one center it should wait for the ping_completed function to...
1
by: Krish | last post by:
All, I have an offline application that works online for some data syncronization. For data syncronization I access a webservice. I want to show whether my application is online or not by checking...
4
by: =?Utf-8?B?QWxleCBLLg==?= | last post by:
Hi all I need a simple program that allows me to check if an IP address is pingable. I am not going to send/receive anything to the remote host, just check if it is visible. Something like...
6
by: Dave Marden | last post by:
I currently use this routine in vbscript to ping computers and get the status of ping to determine whether to try to backup a machine, I am trying to change it to work with vb2003.net I am...
11
by: Fuzz13 | last post by:
I am using a Ping member to ping a website from 2 different computers. The first computer is the websites server where all the files etc for the website are stored. The second computer running the...
6
by: munkee | last post by:
I am sending semi automated emails within my access database using our companies internal smtp server. One of the issues I had was capturing whether people were connected to the lan to be able to...
1
by: dawood munavar | last post by:
#!/usr/bin/perl use Net::Ping; use Fcntl; print "enter the location of the file \n"; $loc = <STDIN>; sysopen(FILEIN, $loc, O_RDONLY); my @ip_array = <FILEIN>;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.