Win XP SP3 上的 Ping 广播
我正在尝试在 WinXP SP3 上 ping 广播地址 255.255.255.255。
如果我使用命令行,则会收到主机错误:
C:\>ping 255.255.255.255
Ping request could not find host 255.255.255.255. Please check the name and try again.
如果我尝试使用 iphlpapi 的 C++ 程序,IcmpSendEcho()
会失败,GetLastError
返回 11010 IP_REQ_TIMED_OUT
代码>.
HANDLE h = ::IcmpCreateFile();
IPAddr broadcast = inet_addr( "255.255.255.255" );
BYTE payload[ 32 ] = { 0 };
IP_OPTION_INFORMATION option = { 255, 0, 0, 0, 0 };
// a buffer with room for 32 replies each containing the full payload
std::vector< BYTE > replies( 32 * ( sizeof( ICMP_ECHO_REPLY ) + 32 ) );
DWORD res = ::IcmpSendEcho( h,
broadcast,
payload,
sizeof( payload ),
&option,
&replies[ 0 ],
replies.size(),
1000 );
::IcmpCloseHandle( h );
我可以 ping 本地广播 192.168.0.255
没有问题。
我需要做什么才能 ping 全球广播?
谢谢, 保罗·H
I'm trying to ping the broadcast address 255.255.255.255 on WinXP SP3.
If I use the command line, I get host error:
C:\>ping 255.255.255.255
Ping request could not find host 255.255.255.255. Please check the name and try again.
If I try a C++ program using the iphlpapi, IcmpSendEcho()
fails and GetLastError
returns 11010 IP_REQ_TIMED_OUT
.
HANDLE h = ::IcmpCreateFile();
IPAddr broadcast = inet_addr( "255.255.255.255" );
BYTE payload[ 32 ] = { 0 };
IP_OPTION_INFORMATION option = { 255, 0, 0, 0, 0 };
// a buffer with room for 32 replies each containing the full payload
std::vector< BYTE > replies( 32 * ( sizeof( ICMP_ECHO_REPLY ) + 32 ) );
DWORD res = ::IcmpSendEcho( h,
broadcast,
payload,
sizeof( payload ),
&option,
&replies[ 0 ],
replies.size(),
1000 );
::IcmpCloseHandle( h );
I can ping the local broadcast 192.168.0.255
with no problem.
What do I need to do to ping the global broadcast?
Thanks,
PaulH
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,这在 Windows 中不起作用。在 Linux 操作系统中,您可以 ping 255.255.255.255,但路由协议不会在本地网络之外中继 255.255.255.255 广播。
你想达到什么目的?您准备好让互联地球上的每台计算机都会做出响应吗? 我很害怕...
顺便说一句,您应该做好准备,即使在本地网络中也没有人会响应广播 ping。 这个关于 SF 的问题可能会有用。
This doesn't work in Windows as I know. In Linux OS you can ping 255.255.255.255, but routing protocol will not relay 255.255.255.255 broadcasts outside of the local network.
What are you trying to achieve? Are you ready that every computer on the connected earth will respond? I'm scared...
By the way, you should be ready that no one will respond to the broadcast ping even in the local network. This question on SF could be useful.
广播 UDP 已经过时了大约 20 年。通过路由器到达另一个子网的可能性极小。
Broadcast UDP has been obsolete for about 20 years. It is most unlikely to get through a router to another subnet.