python获取公网ip的几种方式

目录

1

from urllib2 import urlopen
my_ip = urlopen('http://ip.42.pl/raw').read()
print 'ip.42.pl', my_ip

2

from json import load
from urllib2 import urlopen
my_ip = load(urlopen('http://jsonip.com'))['ip']
print 'jsonip.com', my_ip

3

from json import load
from urllib2 import urlopen
my_ip = load(urlopen('http://httpbin.org/ip'))['origin']
print 'httpbin.org', my_ip

4

from json import load
from urllib2 import urlopen
my_ip = load(urlopen('https://api.ipify.org/?format=json'))['ip']
print 'api.ipify.org', my_ip

天国旅立下载
「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
Python