如何从捕获的数据包中获取短信?

时间:2019-04-21 09:41:03

标签: c# sockets networking tcp packet

我制作了一个程序,可以从服务器的同一程序发送/接收消息。使用的类TcpClient和NetworkStream。我以这种方式发送消息,一切正常。

byte[] messagebuffer = Encoding.ASCII.GetBytes(txtMessage.Text);
stream.Write(messagebuffer, 0, messagebuffer.Length);

来自Internet嗅探器的示例,它拦截来自指定IP的数据包。

socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
socket.Bind(new IPEndPoint(IPAddress.Parse(comboBox1.SelectedItem.ToString()), int.Parse(tbPort.Text)));
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);

byte[] byInc = new byte[] { 1, 0, 0, 0 };
byte[] byOut = new byte[4];
buffer = new byte[4096];
socket.IOControl(IOControlCode.ReceiveAll, byInc, byOut);
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, OnReceive, null);

我收到了截获的数据缓冲区,并将其从Internet上传到ready类:  https://pastebin.com/qCQ5eWiS

我从客户端/服务器发送一条消息:“测试”,并用嗅探器拦截该软件包。我试图显示数据,但显示乱码。有什么问题吗?

0 个答案:

没有答案