获取137端口收到的广播消息的源IpAddress(Fetching Source IpAddress of the broadmessage meesage recieved on port 137

编程入门 行业动态 更新时间:2024-10-22 22:57:50
获取137端口收到的广播消息的源IpAddress(Fetching Source IpAddress of the broadmessage meesage recieved on port 137)

我试图从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

更多推荐

本文发布于:2023-07-31 20:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1347253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   消息   Fetching   IpAddress   recieved

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!