使用原始套接字的纯python icmp ping实现。
python3-ping的Python项目详细描述
使用原始套接字的纯python ping实现。
注意,ICMP消息只能从以根用户身份运行的进程发送 (在Windows中,必须以“管理员”身份运行此脚本)。
的原始版本用法
~/python3-ping$ sudo ./ping.py google.com PYTHON-PING google.com (209.85.148.99): 55 data bytes 64 bytes from google.com (209.85.148.99): icmp_seq=0 ttl=54 time=56.2 ms 64 bytes from google.com (209.85.148.99): icmp_seq=1 ttl=54 time=55.7 ms 64 bytes from google.com (209.85.148.99): icmp_seq=2 ttl=54 time=55.5 ms ----google.com PYTHON PING Statistics---- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip (ms) min/avg/max = 55.468/55.795/56.232 ~/python3-ping]# ./ping.py usage: ping.py [-h] [-q] [-c COUNT] [-W TIMEOUT] [-s PACKET_SIZE] destination ping.py: error: the following arguments are required: destination
待办事项
- 重构ping.py
- 使用输出解析器添加“supprocess ping”
新功能
- cli接口->;感谢Yu Jie Lin使用argParse模块添加此功能