【发布时间】:2011-10-05 13:16:37
【问题描述】:
我想编写一个 C 或 C++ 程序,给定一个 IP 地址,对其进行 Ping,然后根据 Ping 是否成功执行进一步的操作。 这个怎么做?
【问题讨论】:
-
根据您想要完成的任务,查看 nmap 源可能会很有趣。
标签: c++ c network-programming ping
我想编写一个 C 或 C++ 程序,给定一个 IP 地址,对其进行 Ping,然后根据 Ping 是否成功执行进一步的操作。 这个怎么做?
【问题讨论】:
标签: c++ c network-programming ping
在The Ping Page 上大放异彩,它有一个指向原始Unix ping(8) 上的full source 的链接。
【讨论】:
编辑我在发帖后看到,你在 Ubuntu 上。但是,搜索此问题的人可能仍会发现这些链接对 Windows 很有帮助。
Ping:原始套接字方法:http://tangentsoft.net/wskfaq/examples/rawping.html
使用 Icmp.dll 实现 Internet Ping:http://support.microsoft.com/default.aspx?scid=kb;en-us;170591
IcmpSendEcho 函数:http://msdn.microsoft.com/en-us/library/aa366050%28VS.85%29.aspx
Ping for Windows:http://www.codeproject.com/KB/IP/winping.aspx
【讨论】:
这篇文章很旧,但我认为以下链接将帮助未来的人们寻找有关如何创建 Ping 请求的良好解释。
【讨论】:
int main() {
int x = system("ping -c1 -s1 8.8.8.8 > /dev/null 2>&1");
if (x==0){
cout<<"success"<<endl;
}else{
cout<<"failed"<<endl;
}
从您的 IP 地址替换 8.8.8.8
【讨论】: