python脚本获取本机公网ip
 

1.获取公网IP地址方式,访问:http://txt.go.sohu.com/ip/soip

 

2.代码实现

import requests

import re

req=requests.get("http://txt.go.sohu.com/ip/soip")

ip=re.findall(r'\d+.\d+.\d+.\d+',req)

print(ip[0])

 

1.获取公网IP地址方式,访问:http://txt.go.sohu.com/ip/soip

 

2.代码实现

import requests

import re

req=requests.get("http://txt.go.sohu.com/ip/soip")

ip=re.findall(r'\d+.\d+.\d+.\d+',req)

print(ip[0])