查看了校园网认证的网页源码,搞清楚认证过程。使用python写个认证的脚本,主要还是自己用起来比较方便,老是拿网页还是挺烦的。
一、脚本在Python3环境下运行
1.登录命令
python njunet.py -do l -user ab1234567 -passwd 0123456
2.登出命令
python njunet.py -do logout
3.查看在线信息
python njunet.py -do i
二、源码
#-*-encoding:utf-8-*-
import argparse
import urllib.request, urllib.parse, urllib.error
import time, ast
username = ''
password = ''
portal_url = 'http://p.nju.edu.cn'
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
}
language = 'cn'
io_url = '/portal_io/'
auth_type = 'pap'
pageNum = 5
userinfo = None
selfservice = None
service = {
'current' : None,
'next' : None,
'chose' : []
}
refresh = True,
server_time = None
#https://www.cnblogs.com/MnCu8261/p/5880764.html
def long2ip(long):
floor_list=[]
yushu=long
for i in reversed(range(4)):
res=divmod(yushu,256**i)
floor_list.append(str(res[0]))
yushu=res[1]
return '.'.join(floor_list)
def letterorcharacter(ch):
if ord(ch) <= 127 and ord(ch) >= 0:
return 1
else :
return 0
def myFormatPrint(string, length=0, align='l', symbol=' '):
i = 0
temp = ''
str_len = len(string)
while i < length:
temp += symbol
i += 1
i = 0
str_sp = 0
while i < str_len:
if letterorcharacter(s



被折叠的 条评论
为什么被折叠?



