使用Python获取自己的IP
需要引入:import re,urllib2from subprocess import Popen, PIPE
内网IP:re.search('/d+/./d+/./d+/./d+',Popen('ipconfig', stdout=PIPE).stdout.read()).group(0)外网IP:re.search('/d+/./d+/./d+/./d+',urllib2.urlopen("http://www.whereismyip.com").read()).group(0)内网IP是通过调用shell命令来获取,使用os.system无法交互,所以使用Popen外网IP是通过访问whereismyip来获取,使用urllib2来访问该网站
页:
[1]