Finding a public facing IP address in Python?

2019-01-23 03:54发布

How can I find the public facing IP for my net work in Python?

8条回答
地球回转人心会变
2楼-- · 2019-01-23 04:14

This is simple as

>>> import urllib
>>> urllib.urlopen('http://icanhazip.com/').read().strip('\n')
'xx.xx.xx.xx'
查看更多
时光不老,我们不散
3楼-- · 2019-01-23 04:23

whatismyip.org is better... it just tosses back the ip as plaintext with no extraneous crap.

import urllib
ip = urllib.urlopen('http://whatismyip.org').read()

But yeah, it's impossible to do it easily without relying on something outside the network itself.

查看更多
登录 后发表回答