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

后端 未结 7 1450
梦毁少年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:57

    I like the requests package with http://ip.42.pl/raw

    import requests
    requests.get('http://ip.42.pl/raw').text
    

提交回复
热议问题