Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 写端口侦听器_C#_Sockets - Fatal编程技术网

C# 写端口侦听器

C# 写端口侦听器,c#,sockets,C#,Sockets,我编写了一个类似于嗅探器的应用程序,它可以监听端口并向用户显示在计算机和internet之间传输的信息,如源和目标ip 如何将其更改为检索url地址而不是ip地址?是否可能? 我用插座工作 private byte[] byUDPData = new byte[4096]; //Data carried by the UDP packet public UDPHeader(byte [] byBuffer, int nReceived) { MemoryStr

我编写了一个类似于嗅探器的应用程序,它可以监听端口并向用户显示在计算机和internet之间传输的信息,如源和目标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相同的嗅探功能。

当您说

url地址而不是ip地址

你是说dns名称吗?在这种情况下,您需要使用dns类和
dns.GetHostEntry
方法从IP地址查找名称


如果您正在查找URL信息,那么正如@David Schwartz所说,您必须解码您捕获的所有数据,这些数据中可能有URL,也可能没有URL。

您必须重新组合应用程序级数据,并从HTTP请求中提取URL。这是一个相当大的工作(因为你必须复制几个协议层的功能),你应该认真考虑修改(或使用)现有的工具。你的问题读起来像“我有一个锤子和一些2x4,我想建立一个吊桥。”不仅仅是http不运行udp的事实。。。