Home > Backend Development > Python Tutorial > Python's simple method to obtain your own external network IP

Python's simple method to obtain your own external network IP

高洛峰
Release: 2017-02-22 16:35:22
Original
1409 people have browsed it

The example in this article describes how Python simply obtains its own external network IP. Share it with everyone for your reference, the details are as follows:

#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()
Copy after login


For more related articles on how to simply obtain your own external network IP in Python, please pay attention PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template