.net sniffing: attempt to create socket causes access error

I work with code from Any good .net package sniffs?

As part of the project and offline, I am trying to create a socket using the following line:

mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP); 

On this line, I immediately get an exception

 System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 

I do not think this is a problem with account permissions. I can run Fiddler in this account just fine.

Is it right to open the listener for outgoing packets? If so, what do I need to do to avoid a permission error?

Update : .net 4.0 Windows 7 Home Premium

+4
source share
1 answer

You cannot create raw sockets without administrative privileges.

Raw sockets offer the ability to manipulate the underlying transport, so they can be used for malicious purposes that pose a security risk. Therefore, only members of the Administrators group can create SOCK_RAW sockets in Windows 2000 and later.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx

I'm not sure what Fiddler is, but it can use UAC to automatically gain administrator privileges.

Also, if you are looking for a decent .net package sniffer, you can check out SharpPcap , which wraps the already awesome libpcap.

+3
source

All Articles