|
 |
|
|
 |
|
|
 |
|
|
Took me awhile to figure this out.. Only to find out someone else had figured this out on the SECOND page of the messages.. 
Add this below line 295 of Ping.Cs file.
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, this.pingTimeout);
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
First of all, thanks for this code. Itt seems you worked really hard. But there is a serious issue.
If you create multiple threads which creates a Ping object and call PingHost, the first successful ping operation automatically makes other PingHost calls from other threads incorrectly successful too although they can fail. The problem is below as I debuged.
in "SendPackets()" method at line "byteCount = socket.ReceiveFrom(receiveBuffer, 256, SocketFlags.None, ref client);" receives response although dead hosts are tried to be pinged. That's reason is ping response (pong) was received from another alive host which is pinged from another thread.
Shortly never call this code simultaneously. I am looking for a solution and will share if I find.
With my best wishes..
Gokcer Gokdal
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Well i m trying to embed this code in a web application but it gives me different result then window application
when i click ping it said sent 4 lost 4 in a web application and in windows applicaiton sent 4 recieved 4
so plz help me y it is happening like it
jk
|
| Sign In·View Thread·PermaLink | 1.33/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
I am logged in as an administrator to the source computer performing the ping, but I still get the Socket Exception:
"An attempt was made to access a socket in a way forbidden by its access permissions"
Any ideas why?
Also, I see that you were looking into the iphlpapi.dll, any progress? :->
Thanks!
|
| Sign In·View Thread·PermaLink | 2.33/5 (2 votes) |
|
|
|
 |
|
|
Hmmm, now that I think more about it, I am trying to use this program via a web application, so it must be using the permissions of the ASPNET user account.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
If you are running this through the ASPNET user account then it's very unlikely that it does have admin rights (unless you specifically made the ASPNET user a member of the Admins).
Had I realized that using sockets requires admin rights (added with XP SP2 I think) I would have parsed the output of the ping command-line app as suggested by another member here.
As to futher development, I'm not currently working on this as .Net V2 now includes a Ping class (see Msdn link).
|
| Sign In·View Thread·PermaLink | 4.00/5 (1 vote) |
|
|
|
 |
|
|
Thanks for the reply. It makes sense to stop development since it is now included in .NET v2. Do you know if the same limitation exists in version 2?
For those who need a solution for gool ol' 1.1 still, where permissions is a problem, I found this: A ping class in VB.Net[^]
You need to manually create a project, copy and paste the code, etc., but it worked for me without modifications. You also need to find and download Microsoft's ICMP.dll[^]
This will do a ping and a tracert. While not as powerful as Wesley's, you can get around the permissions problem.
-- modified at 8:58 Wednesday 12th April, 2006
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Regardless of what the timeout property is set to, the synchronous PingHost will wait forever for a response. Looking at the code, this timeout seems only to be used for sending the ICMP packet, which we seldom care about. It would be better if the timeout is for both sending and receiving as in Windows ping.
/ Roland
|
| Sign In·View Thread·PermaLink | 5.00/5 (2 votes) |
|
|
|
 |
|
|
If someone is interested, I have made a lot of fixes to this code. 1-Larges ping with the current code is 256 - now Protocol level limmitation (65535) 2-Ideffinit wait for lost ping requests- now equlaes timaout set. 3-It sometimes happen that a ping will timout and later the packet is recived after the seccond reques is sent. the code now uses the sequince number in the ICMP packet to keep track of the packets. 4-current if the ICMP responce is an error or a redirect, the Ping will return successfull. I have implemented the ICMP error messages.
If interested, mail me at johanroos@bluebottle.com
|
| Sign In·View Thread·PermaLink | 4.20/5 (5 votes) |
|
|
|
 |
|
|
I've put the Ping class to ping an unreachable host. All the PingResponse events give me a timeout result. But the PingCompleted event tells that not all the packets have been lost. What is wrong? Am I misinterpreting the results? Thank you.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
If I ping ip1 in one thread, ping ip2 in another thread, and ip1 is connected, ip2 is not connected, Ping Component always return all ok. But if I only ping ip1 , or only ping ip2, it's right. why?
void btn_click(object sender, System.EventArgs e){ ThreadStart s = new ThreadStart(_run); Thread t = new Thread(s); t.Start(); ThreadStart s2 = new ThreadStart(_run2); Thread t2 = new Thread(s2); t2.Start(); }
void _run() { ... ;// ping ip1}
void _run2() { ... ;// ping ip2}
thanks!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
The just released .NET Framework 2.0 contains the System.Net.NetworkInformation.Ping class.
Just so you all know.
/Kristofer
|
| Sign In·View Thread·PermaLink | 4.00/5 (2 votes) |
|
|
|
 |
|
|
Kristofer Liljeblad wrote: The just released .NET Framework 2.0 contains the System.Net.NetworkInformation.Ping class.
Just so you all know.
Right! And here is how to use it:
VB.NET:
Dim ping1 As New System.Net.NetworkInformation.Ping Dim reply1 As System.Net.NetworkInformation.PingReply Try reply1 = ping1.Send("MachineName") MessageBox.Show(reply1.Address.ToString()) Catch ex As Exception MessageBox.Show(ex.Message.ToString) End Try
C#:
System.Net.NetworkInformation.Ping ping1 = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply reply1; try { reply1 = ping1.Send("MachineName"); MessageBox.Show(reply1.Address.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString); }
Thanks for the info.
Pete Soheil DigiOz Multimedia http://www.digioz.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Not bad, but like a lot of stuff, specially written in C# unfortunately with unmanaged code. Maybe you can redesign your code. WIN32 will be over in time .
Cheers
Tom
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Why are you sending 60 bytes in the ping packet? When I ping from the command window it only uses 32 bytes. Your class seems very good. Very interesting reading.
Thanks, Einar
|
| Sign In·View Thread·PermaLink | 4.00/5 (3 votes) |
|
|
|
 |
|
|
First of all, thanks for sharing this code. I converted that MSDN article's C# code to VB to get ping functionality but it was unreliable and slow. Your implementation is WAY faster and more reliable.
I ran into problems when I tried to implement simple async calls to try to keep my UI responsive when pinging unreachable hosts.
I'm using this code (trimmed for posting):
Dim png As New BS.Utilities.Ping
Dim ar As IAsyncResult ar = png.BeginPingHost(Nothing, Host, Retries) Do While Not ar.IsCompleted Application.DoEvents() Loop
Dim rsp As BS.Utilities.PingResponse rsp = png.EndPingHost(ar) png.Dispose()
But EndPingHost always returns Nothing whether the computer is reachable or not. As I understand the whole async Begin... End... menthods that code should work. The ar.IsCompleted property does get set correctly and EndPingHost doesn't raise an error, it just always returns Nothing.
I also tried it using a callback but in the callback method I found that EndPingHost still returned Nothing.
What am I doing wrong? Anything obvious? I suppose I can dig into your code and try to figure it out but I thought I'd ask here to see if I'm being a doofus.
Steve
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Your code looks fine to me. I would hook into the error event to see if you're getting an exception while the ping is running. If no exceptions are getting thrown then I would step into the ping source to see what's failing.
Also note that as mentioned below you must be logged in as an Admin because I use raw sockets.
Wes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hey Wesley, Just wanted to drop you a quick line of thanks, I have been pulling my hair looking for a decent ping component and you have provided just that!
Thanks,
Ben
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
You should check the Address of the client variable after ReceiveFrom, and discard if it doesn't match. Also, you could put Process Id, or thread Id in Identifier property and check it after ReceiveFrom. Of course, you have to recalculate Checksum if you change Identifier property. HTH, Tom
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |