Read IP address of all website currently visted
Hi,
I am trying to make an application which tries to read the website ip's currentely visited. I have found an example of packet sniffer in c# (http://www.codeproject.com/KB/IP/CSNetworkSniffer.aspx).
My problem is that i dont want to run the call conitnuously. So i kept the call in a timer. All works fine, but when i plugged in my wifi internet connection( in addtion to my current lan connection), i was not able to view webpage. So i modified the code such a way to montior the ip through all the port. Then i am getting
Code:
System.Net.Sockets.SocketException: An invalid argument was supplied at System.Net.Sockets.Socket.IOControl(Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue) at System.Net.Sockets.Socket.IOControl(IOControlCode ioControlCode, Byte[] optionInValue, Byte[] optionOutValue)
Here is my code
Code:
private void checkIP(string strIP)
{
//mainSocket.Close();
// mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
mainSocket.Bind(new IPEndPoint(IPAddress.Any,0));// Parse(strIP), 0));
mainSocket.SetSocketOption(SocketOptionLevel.IP, //Applies only to IP packets
SocketOptionName.HeaderIncluded, //Set the include the header
true); //option to true
byte[] byTrue = new byte[4] { 1, 0, 0, 0 };
byte[] byOut = new byte[4] { 1, 0, 0, 0 }; //Capture outgoing packets
mainSocket.IOControl(IOControlCode.ReceiveAll, //Equivalent to SIO_RCVALL constant
//of Winsock 2
byTrue,
byOut);
mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
timer1Sec.Enabled = true;
}
/*************************************************************/
private void OnReceive(IAsyncResult ar)
{
try
{
int nReceived = mainSocket.EndReceive(ar);
//Analyze the bytes received...
ParseData(byteData, nReceived);
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message, "MJsniffer", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
checkIP is called from a timer. I am getting exception in mainSocket.IOControl