[英]write port listener
我写了一个像嗅探器这样的应用程序,它可以侦听端口并向用户显示在计算机和Internet之间传输的信息,例如源IP和目标IP。
我如何更改它以检索URL地址可以代替IP地址吗? 我使用插座。
private byte[] byUDPData = new byte[4096]; //Data carried by the UDP packet
public UDPHeader(byte [] byBuffer, int nReceived)
{
MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived);
BinaryReader binaryReader = new BinaryReader(memoryStream);
//The first sixteen bits contain the source port
usSourcePort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the destination port
usDestinationPort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the length of the UDP packet
usLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the checksum
sChecksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//Copy the data carried by the UDP packet into the data buffer
Array.Copy(byBuffer,
8,
byUDPData,
0,
nReceived - 8);
}
通常不需要这样做。 看看Wire Shark 。 如果找不到确切的需求,则可以编写自己的协议分析器和其他加载项。
另外,看看WinPCap ,它使您的应用程序可以访问与Wire Shark相同的嗅探功能。
当你说
网址而不是IP地址
您的DNS名称是什么意思? 在这种情况下,您需要使用dns类和Dns.GetHostEntry
方法从IP地址中查找名称。
如果您要查找URL信息,那么就像@David Schwartz所说的那样,您将必须对捕获的所有数据进行解码,其中可能有也可能没有URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.