1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
from urllib2 import urlopen from json import load my_ip = urlopen('http://ip.42.pl/raw').read() print 'ip.42.pl/raw\t', my_ip my_ip = load(urlopen('https://jsonip.com'))['ip'] print 'jsonip.com\t', my_ip #my_ip = load(urlopen('https://httpbin.org/ip'))['origin'] #print 'httpbin.org/ip\t', my_ip my_ip = load(urlopen('https://api.ipify.org/?format=json'))['ip'] print 'api.ipify.org/?format=json\t', my_ip import re import os def my_ip(): get_ip_method = os.popen('curl -s ip.cn') get_ip_responses = get_ip_method.readlines()[0] get_ip_pattern = re.compile(r'\d+\.\d+\.\d+\.\d+') get_ip_value = get_ip_pattern.findall(get_ip_responses)[0] return get_ip_value my_ip = my_ip() print 'ip.cn aliyun\t', my_ip |