Guest User

Untitled

a guest
Aug 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Capturing raw sockets (SOCK_RAW) without Administrator account
  2. public void startSniffer()
  3. {
  4. bContinueCapturing = true;
  5.  
  6. mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
  7.  
  8. mainSocket.Bind(new IPEndPoint(IPAddress.Parse(Properties.Settings.Default.IPaddr), 0));
  9. mainSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);
  10.  
  11. byte[] byTrue = new byte[4] { 1, 0, 0, 0 };
  12. byte[] byOut = new byte[4] { 1, 0, 0, 0 };
  13.  
  14.  
  15. mainSocket.IOControl(IOControlCode.ReceiveAll, byTrue, byOut);
  16.  
  17. mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
  18.  
  19. }
  20.  
  21. public void OnReceive(IAsyncResult ar)
  22. {
  23. int nReceived = mainSocket.EndReceive(ar);
  24.  
  25. ParseData(byteData, nReceived);
  26.  
  27. if (bContinueCapturing)
  28. {
  29. byteData = new byte[4096];
  30.  
  31. mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
  32. }
  33.  
  34. }
Add Comment
Please, Sign In to add comment