自动登陆校园网:socketError: [ERRNO 107] ?
-
按照示例WIFI中的 TCPclient 示例修改了以下,用来自动登陆校园网。以下是源码:
源码:
import sockethost="ngw.bupt.edu.cn"
port=80postData="POST /login HTTP/1.1\r\n"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"Accept-Language: zh-CN,zh;q=0.9\r\n"
"Cache-Control: max-age=0\r\n"
"Connection: keep-alive\r\n"
"Content-Length: 41\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Cookie: Hm_lvt_41e71a1bb3180ffdb5c83f253d23d0c0=1531817431; __lnkrntdmcvrd=-1; SessionId=4df2839f394641e7\r\n"
"Host: ngw.bupt.edu.cn\r\n"
"Origin: http://ngw.bupt.edu.cn\r\n"
"Referer: http://ngw.bupt.edu.cn/index\r\n"
"Upgrade-Insecure-Requests: 1\r\n"
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36\r\n\r\n"
"user=2016211970&pass=033654&line=CUC-BRAS"def loginToSchoolNet():
try:
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
addr = socket.getaddrinfo(host,port)[0][-1]
print("目标地址",addr)
client.settimeout(100)
client.connect((host,port))
print("已连接到 ngw.bupt.edu.cn")client.send(postData) print("get response:",client.recv(1024)) client.close() return 1 except OSError as e: print("login socket error:",e) help(e) client.close() return -1
运行时抛出异常:
socket error: [Errno 107] ENOTCONN
object [Errno 107] ENOTCONN is of type OSErroremmmwhy....怎么肥西,运行示例的TCPclient没有问题的。。
-
不知道,校园网是其他的认证,我不知道怎么做。
你应该用路由器。