2009年7月18日星期六

SHOW ME THE IP

从内网获得路由器的广域网IP地址的Python脚本(仅限特定硬件和特定固化软件):
#! /usr/bin/env python
"""
Get my IP address from my TP-Link TL-R402 router.
Pan Yongzhi@ Jul 18, 2009
"""
import urllib2
x = urllib2.HTTPPasswordMgrWithDefaultRealm()
x.add_password(None, 'http://192.168.1.1', 'user', 'pass')
auth = urllib2.HTTPBasicAuthHandler(x)
opener = urllib2.build_opener(auth)
urllib2.install_opener(opener)
flob = urllib2.urlopen('http://192.168.1.1/userRpm/StatusRpm.htm')
"""IP address contained in line 75 of the web page, looks like this:
0, "00-21-27-3C-01-A5", "221.217.204.232", 3, "255.255.255.255", 0, 0, "221.217.204.232", 0, 1, 0, "202.106.46.151, 202.106.195.68", "0 day 00:19:31", "up",
"""
print flob.readlines()[74].split(',')[2].strip().strip('"')

没有评论:

发表评论