- 论坛徽章:
- 0
|
我是电信光纤宽带用户,用web认证不支持多台机器上网。参考了网上的资料,想写一个python的小程序,可以自动获取宽带路由器的外网IP,自动发送认证信息。宽带路由器登录时会要用户名密码,否则就连不上,我通过使用嗅探器抓包把认证过的'Authorization'值取出放在我的程序里能连上路由器,但通用性太差。有什么好方法可以解决吗?
我的小程序如下:
#ptyhon
import urllib
import httplib
params = urllib.urlencode({})
headers = {'Accept': 'text/html', 'User-Agent': 'Mozilla','Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Basic amh1aTpqaHVpMTIzNA=='}
conn = httplib.HTTPConnection("192.168.1.1")
#print headers
conn.request("GET","/userRpm/StatusRpm.htm",params,headers)
#id (conn)
r1 = conn.getresponse()
a = r1.read()
#print a
b = a.find("222")
#print b
c = a.find("</td",b)
#print c
d = a[b:c]
print d
params = urllib.urlencode({'connectname': '',
'consumeright': 0,
'separatecard': 0,
'needActiveX' : 1,
'clienttype' :1,
'cookiedate' :3650,
'localip': d,
'httpIP' :d,
'isPNP':0,
'username': "njkd107089173",
'password': "1976"})
headers = {'Accept': 'text/html', 'User-Agent': 'Mozilla',
'Content-Type': 'application/x-www-form-urlencoded'}
server = '218.2.135.36'
path = '/secu/webLogin.jsp'
conn = httplib.HTTPConnection(server)
conn.request("POST", path, params, headers)
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
print data1
conn.close() |
|