我想在我的服务器上嗅探数据包,我只是尝试了一些包装,用于接收数据包,如MJSniffer,SharpCap,但这些都显示我错误的数据
我不得不写服务器 - 客户端exe来检查收到的数据包,我很惊讶。例如,我发送到以下数据包
client_.Send(new byte[] { 0x01 , 0xC1 , 0x12 });
并且跟随嗅探器接收的数据包,并且它经常显示不同的字节。我试图将它们转换为十六进制值并且结果相同
136, 184, 7, 50, 226, 41, 144, 15, 202, 11, 76, 178, 80, 16, 1, 0, 18, 142, 0, 0
这是什么意思?我可以收到像0x01 0xC1 0x12
嗅探代码:
public void OnReceive(IAsyncResult ar)
{
int nReceived = this._SocketCnn.EndReceive(ar);
ParseData(byteData, nReceived);
byteData = new byte[4096];
this._SocketCnn.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None,
new AsyncCallback(OnReceive), null);
}
public void ParseData(byte[] byteData, int nReceived)
{
IPHeader ipHeader = new IPHeader(byteData, nReceived);
if (ipHeader.ProtocolType == Protocol.TCP)
{
TCPHeader tcpHeader = new TCPHeader(ipHeader.Data, (int)ipHeader.MessageLength);
if (Convert.ToInt32(tcpHeader.SourcePort) == this._ParamsCnn.Port)
{
TCPHeader tcpHeader_ = new TCPHeader(byteData, nReceived);
ReturnData returnMsg_ = new ReturnData();
returnMsg_.ReceivedData = ipHeader.Data;
returnMsg_.SourceIPAddress = ipHeader.SourceAddress.ToString();
returnMsg_.SourcePort = Convert.ToInt32(tcpHeader.SourcePort);
returnMsg_.TargetIPAddress = ipHeader.DestinationAddress.ToString();
returnMsg_.TargetPort = Convert.ToInt32(tcpHeader.DestinationPort);
OnDataReceivedEvent(returnMsg_);
}
}
}