Ping a site in Python?

前端 未结 15 2225
我寻月下人不归
我寻月下人不归 2020-11-22 09:22

How do I ping a website or IP address with Python?

15条回答
  •  既然无缘
    2020-11-22 09:40

    If you want something actually in Python, that you can play with, have a look at Scapy:

    from scapy.all import *
    request = IP(dst="www.google.com")/ICMP()
    answer = sr1(request)
    

    That's in my opinion much better (and fully cross-platform), than some funky subprocess calls. Also you can have as much information about the answer (sequence ID.....) as you want, as you have the packet itself.

提交回复
热议问题