我试图从DSL调制解调器发送的广播数据包中获取IP地址,并使用UDP协议在端口137上接收。 当连接存在时,我能够读取IP地址。
但是,在未识别的网络状态下,当我的调制解调器配置为DHCP,并且允许特定范围的IP,并且我的机器上的设置是自动检测:
我在读取广播消息时获得了机器的默认本地IP地址。 这将从169开始。
注意:我正在重新启动调制解调器以接收广播消息。
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint iep = new IPEndPoint(IPAddress.Any, 137); sock.Bind(iep); EndPoint ep = (EndPoint)iep; int iLoopCount=0; while (iLoopCount <= 10000) { Console.WriteLine("Ready to receive…"); byte[] data = new byte[1024]; int recv = sock.ReceiveFrom(data, ref ep); string stringData = Encoding.Default.GetString(data, 0, recv); Console.WriteLine("{1}: from: {0}",((IPEndPoint)ep).Address.ToString(),DateTime.Now.ToString()); iLoopCount++; // Console.WriteLine(sock.RemoteEndPoint.ToString()); } sock.Close(); Console.Read();I am trying to fetch the IP address from the broadcast packets sent by a DSL modem and received on port 137 using UDP protocol. I am able to read the IP address when connectivity is present.
However, in unidentified network state, when my modem is configured for DHCP, and a specific range of IPs are allowed, and setting on my machine is auto-detect:
I get the default Local IP Address of the machine on reading the broadcast messages. That would be starting with 169.
Note: I am restarting the modem in order to receive the broadcast messages.
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint iep = new IPEndPoint(IPAddress.Any, 137); sock.Bind(iep); EndPoint ep = (EndPoint)iep; int iLoopCount=0; while (iLoopCount <= 10000) { Console.WriteLine("Ready to receive…"); byte[] data = new byte[1024]; int recv = sock.ReceiveFrom(data, ref ep); string stringData = Encoding.Default.GetString(data, 0, recv); Console.WriteLine("{1}: from: {0}",((IPEndPoint)ep).Address.ToString(),DateTime.Now.ToString()); iLoopCount++; // Console.WriteLine(sock.RemoteEndPoint.ToString()); } sock.Close(); Console.Read();最满意答案
在http://www.codeproject.com/Articles/17031/A-Network-Sniffer-in-C找到我的问题的答案
Found the answer to my question at http://www.codeproject.com/Articles/17031/A-Network-Sniffer-in-C
更多推荐
发布评论