使用Python获取机器的外部IP地址
- 论坛
- 使用Python获取机器的外部IP地址
18 浏览
使用Python获取机器的外部IP地址
寻找一种更好的方法来获取机器当前的外部IP地址...下面的方法可以工作,但我不想依赖外部网站来收集信息...我只能使用Mac OS X 10.5.x捆绑的标准Python 2.5.1库。
import os import urllib2 def check_in(): fqn = os.uname()[1] ext_ip = urllib2.urlopen('http://whatismyip.org').read() print ("Asset: %s " % fqn, "Checking in from IP#: %s " % ext_ip)