当前位置:编程学习 > C#/ASP.NET >>

C#编写udp扫描,icmp.ReceiveFrom总是接收不到?哪位大侠帮个忙

现在我想用C#实现UDP扫描,部分代码如下:
 Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                    Socket icmp = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp);
                    byte[] data = Encoding.ASCII.GetBytes("hello");

                    IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("192.168.1.101"), i);//i为端口
                   //扫描 192.168.1.101
                    IPEndPoint ipeLocal = new IPEndPoint(IPAddress.Any, 0);
                    ep = (EndPoint)ipe;
                    epLocal = (EndPoint)ipeLocal;

                    icmp.Bind(epLocal);
                    icmp.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 500);
                    sock.SendTo(data, ep);//先发送数据包
                    try
                    {                       
                        int len;
                        data = new byte[1024];
                        Console.WriteLine("icmp.Available: {0}", icmp.Available);  
                         len = icmp.ReceiveFrom(data, ref epLocal);//接收ICMP包
                        
                     }
直接建立两个socket,在接受icmp不可达包时 icmp.ReceiveFrom总是收不到,什么原因?是不是底层已经把这个包丢掉了?
哪位大哥帮忙指导一下
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,