本文实例讲述了python简单获取自身外网ip的方法。分享给大家供大家参考,具体如下:
#encoding=utf-8
#author: walker
#date: 2016-03-07
#function: 获取自己的外网ip
import requests
from bs4 import beautifulsoup
#获取外网ip
def getouterip():
url = r’http://www.whereismyip.com/’
r = requests.get(url)
btag = beautifulsoup(r.text, ‘html.parser’, from_encoding=’utf-8′).find(‘b’)
ip = ”.join(btag.stripped_strings)
print(‘ip:’ + ip)
if __name__ == ‘__main__’:
getouterip()
更多python简单获取自身外网ip的方法相关文章请关注php中文网!