使用Python编写西安交通大学教育网外网自动验证器xjtuNetCheck


#导入Python标准库中的httplib
import httplib
import sys
#连接百度主页
conn=httplib.HTTPConnection('www.baidu.com',timeout=60)
#尝试获取验证页面
conn.request('GET','/')
resp1=conn.getresponse()

print(resp1.status)
print(resp1.reason)

checkPage=resp1.read()
print(checkPage)

#检索magiccode
magicpos = checkPage.find('magic')
#如果没有检索到magic,说明正常连接到百度,网络已经验证
if(magicpos==-1):
print('Already authenticate')
sys.exit(0)

first = checkPage.find('\"',magicpos+7)
last = checkPage.find('\"',first+1)
#截取magic
magicCode = checkPage[first+1:last]

print(magicCode)

#使用post方法发送验证数据到网关
postData = {'username':'******','password':'*******','magic':magicCode,'4Tredir':'/'}
param = urllib.urlencode(postData)
conn.request('POST','/',param)
resp2 = conn.getresponse()
print(resp2.status)
print(resp2.reason)
print(resp2.read())

print('Authentication was successful.')

文章作者: 2356
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 2356 !