Hello,
I'm using the following code to perform a ping:
Ping P = new Ping ();
P. pingcompleted + = new pingcompletedeventhandler (p_pingcompleted );
P. sendasync (New IPaddress (New byte [] {10, 2, 1, 25}), 1000 );
P. Dispose ();
And then I'm catching the reply this way:
Void p_pingcompleted (Object sender, pingcompletedeventargs e ){
Pingreply Pr = E. reply;
IPaddress the_pinged_ip = Pr. address;
}
My question, this works perfectly fine on Windows XP, but: on vista I get a reply from 10.2.1.139 (my own PC's address) if the ping fails. (similar to the 'ping' command in DOS)
Is there a way to find the actual ip that was pinged?
Thanks in advance,
Sam
Roger affirmative, mi amigo.
Your solution I believe lies in a parameter of the ping. sendasync method, known as object usertoken.
Change these lines it shocould work fine.
Change your sender:
System. net. IPaddress IP = (New byte [] {10, 2, 1, lowbyte}); // or whatever code works with your for... next loop.
P. sendasync (IP, 1000, ip) // The second "ip" fills the usertoken parameter.
Then in the reply:
System. net. IPaddress callerip = (system. net. IPaddress) E. userstate;
That shoshould work just fine. if you're getting errors, you might have to send it through as a string and convert it back at the other end, but I don't think you'll have to go thru that much trouble. let me know if it doesn' t work.
Oh my f * cking God !!!!
You have no idea how much I love you right now, I 've been searching for something like this for 2 days straight, I 've tried to find ways around und it using self programmed Ping classes with sockets ,.. but nothing worked
This does the trick,
Thank you soooo much.
God bless you,
Kind regards,
Sam