How can I perform a ping or traceroute using native python?

后端 未结 7 1683
走了就别回头了
走了就别回头了 2021-01-05 14:56

I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I\'d prefer a native python solutio

7条回答
  •  花落未央
    2021-01-05 15:40

    The Webb Library is very handy in performing all kinds of web related extracts...and ping and traceroute can be done easily through it. Just include the URL you want to traceroute to:

    import webb
    webb.traceroute("your-web-page-url")
    

    If you wish to store the traceroute log to a text file automatically, use the following command:

    webb.traceroute("your-web-page-url",'file-name.txt')
    

    Similarly a IP address of a URl (server) can be obtained with the following lines of code:

    print(webb.get_ip("your-web-page-url"))
    

    Hope it helps!

提交回复
热议问题