Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Capturing raw sockets (SOCK_RAW) without Administrator account
- public void startSniffer()
- {
- bContinueCapturing = true;
- mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
- mainSocket.Bind(new IPEndPoint(IPAddress.Parse(Properties.Settings.Default.IPaddr), 0));
- mainSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);
- byte[] byTrue = new byte[4] { 1, 0, 0, 0 };
- byte[] byOut = new byte[4] { 1, 0, 0, 0 };
- mainSocket.IOControl(IOControlCode.ReceiveAll, byTrue, byOut);
- mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
- }
- public void OnReceive(IAsyncResult ar)
- {
- int nReceived = mainSocket.EndReceive(ar);
- ParseData(byteData, nReceived);
- if (bContinueCapturing)
- {
- byteData = new byte[4096];
- mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
- }
- }
Add Comment
Please, Sign In to add comment