Win XP SP3 上的 Ping 广播

发布于 2024-10-11 19:21:12 字数 1149 浏览 4 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ㄟ。诗瑗 2024-10-18 19:21:12

据我所知,这在 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.

旧时浪漫 2024-10-18 19:21:12

广播 UDP 已经过时了大约 20 年。通过路由器到达另一个子网的可能性极小。

Broadcast UDP has been obsolete for about 20 years. It is most unlikely to get through a router to another subnet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文