 |
|
 |
An attempt was made to access a socket in a way forbidden by its access permissions......
|
|
|
|
 |
|
 |
As mentioned in other messages, as of Windows XP SP2, sockets require administrator account privileges to work properly.
I would also recommend using the Ping type included with .Net 2.0 and above rather than this type (unless, of course, you must use .Net 1.1).
Cheers,
-Wes
|
|
|
|
 |
|
 |
In windows 7 or Vista you will not get the permisson to ping test because you will get "Cross-thread operation not valid: Control 'cmdCancel' accessed from a thread other than the thread it was created on."
|
|
|
|
 |
|
 |
Hello,
Thanks for the information. Back when I originally wrote this (in the .Net 1.1 timeframe) the single-threaded requirements were not enforced so strictly. Not to say that this isn't a bug, just that the reason you're getting an exception rather than random (infrequent) failures is due to having a more recent version of the .Net framework.
I'm going to guess that you're using .Net 2.0 or greater because I don't think any of the .Net 1.1 versions will throw that exception. If this is true you should really use the System.Net.NetworkInformation.Ping type rather than this component.
-Wes
|
|
|
|
 |
|
 |
You can also replace the EndPing function with this:
private delegate void EndPingDelegate(IAsyncResult result);
private void EndPing(IAsyncResult result)
{
if (this.InvokeRequired)
{
this.Invoke(new EndPingDelegate(EndPing), result);
}
else
{
netMon.EndPingHost(result);
cmdCancel.Visible = false;
cmdPing.Visible = true;
}
}
|
|
|
|
 |
|
 |
Hello Sir..
I am not able to execute this project
my platform is visual studio .net 2008
and the error is
A PROJECT WITH OUTPUT TYPE OF CLASS LIBRARY CANNOT BE STARTED DIRECTLY.
IN ORDER TO DEBUG THIS PROJECT,ADD AN EXECUTABLE PROJECT TO THIS SOLUTION WHICH REFERENCES THE LIBRARY PROJECT. SET THE EXECUTABLE PROJECT AS STARTUP PROJECT..
PLEASE heLP
|
|
|
|
 |
|
 |
What is the issue. Are you illiterate ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
 |
|
 |
You need to set the Project Ping.Test as the startup project.
Cheers,
Filipe Teixeira
|
|
|
|
 |
|
 |
Take a look at System.Net.NetworkInformation.Ping
|
|
|
|
 |
|
|
 |
|
 |
why are some programmers are so lazy they see microsoft components as a ultimate solution and dont want to write their own library .
btw thanks for upload that was gr8 5/5
|
|
|
|
 |
|
 |
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);
|
|
|
|
 |
|
 |
Was just going to offer this advice too...glad I found your message first
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
I believe in IcmpPacket.cs, changing lines 24 and 25 to the following will make the Ping component work in a multithreaded environment.
this.Identifier = (UInt16)Process.GetCurrentProcess().Id; // Use Process ID
this.SequenceNumber = (UInt16)Thread.CurrentThread.GetHashCode(); // Use Thread ID
|
|
|
|
 |
|
 |
why does it takes a lot of time???
thanks a lot
Tal Hakemon
www.WhatIsMySpec.com
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
|
 |
|
 |
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!
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
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).
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |