C# Ping

  • Thread starter Thread starter Tim C
  • Start date Start date
T

Tim C

Is there a way to do a Ping from C# if you are not logged
in as administrator on W2k?

I am trying to do a Ping from C# running under ASP.NET.

I have found several examples on the web, mostly derived
from Lance Olson's code.

The examples use raw sockets and I get a permissions
error: "An attempt was made to access a socket in a way
forbidden by its access permissions".

The KB article Q195445 indicates that raw sockets can only
be opened by an administrator under W2k and there is no
workaround.

I found a reference to ICMP.DLL, but its use is reported
to be highly discouraged. The examples are C++.
 
Tim,

You don't have to be an administrator to ping another machine in
ASP.NET. However, you do have to be running under an account that has the
appropriate permissions to access the network. By default, ASP.NET runs
under the ASPNET local account, which has no rights to the network. To
change this user, you can change the setting in the web.config file for the
directory where the page resides (the impersonation element, as well as the
identity element), or you can make a specific call to the Impersonate method
on the WindowsIdentity class.

Hope this helps.
 
Check out www.mvptools.com. If you like the ping tools, let me know. They
use the ICMP class in the library I will put up their soon. Please provide
feedback. Cheers!
 
Back
Top