How can I get the public IP using python2.7?

后端 未结 7 1447
梦毁少年i
梦毁少年i 2020-11-30 22:43

How can I get the public IP using python2.7? Not private IP.

7条回答
  •  再見小時候
    2020-11-30 22:51

    You can just do this:

    import requests
    print requests.get("http://ipecho.net/plain?").text
    

    Produces:

    XX.XX.XXX.XXX
    

提交回复
热议问题