#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import re
import socket
def get_host_ip(is_cloud_ip=False):
if is_cloud_ip == True:
req=requests.get("http://txt.go.sohu.com/ip/soip")
# print(req.text)
ip=re.findall(r'\d+.\d+.\d+.\d+',req.text)
return(ip[0])
else:
try:
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.connect(('8.8.8.8',80))
ip=s.getsockname()[0]
# print(ip)
return ip
finally:
s.close()
#默认获取本地ip
host_ip = get_host_ip()
print(host_ip )