-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuptNet3.0.py
80 lines (64 loc) · 2.03 KB
/
buptNet3.0.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
#-*- coding: UTF-8 -*-
import requests
import re
import uuid
#from bs4 import BeautifulSoup
agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36'
headers = {'User-Agent': agent}
session = requests.session()
def login(account, pwd):
login_url = 'http://10.3.8.211/'
post_data = {
'DDDDD': account,
'upass': pwd,
'0MKKey': ''
}
login_page = session.post(login_url, post_data, headers=headers)
pattern_span = r'<span.*>(.*)</span>'
status = re.findall(pattern_span, login_page.text)[0].encode('utf-8')
return status
def write_html(content):
with open('buptNet.html', 'w') as f:
f.write(content)
def dataCount():
data_url = 'http://10.3.8.211/'
data_content = session.get(data_url, headers=headers).text
pattern_flow = r"flow='(\d*)\s*'"
flow_str = re.findall(pattern_flow, data_content)[0]
flow = float(flow_str)
flow0 = flow % 1024
flow1 = int(flow - flow0)
flow3 = "."
decimal_temp = str(round(flow0/1024, 3))
decimal_pattern = r'0.(\d*)'
decimal_num = re.findall(decimal_pattern, decimal_temp)[0]
Used_internet_traffic = str(flow1 / 1024 )+ flow3 + decimal_num
return Used_internet_traffic
def get_mac_add():
mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
return ":".join([mac[e:e+2] for e in range(0,11,2)])
def output():
my_mac_add = ""
account = ''
pwd = ''
mac_add = get_mac_add()
if my_mac_add == mac_add:
status = login(account, pwd)
if status == "登 录 成 功":
data_used = dataCount()
total_data = 20 * 1024
data_unused = float(total_data) - float(data_used)
print "Used traffic: " + data_used + " MByte"
print "Remaining traffic: " + str(data_unused) + " MByte"
if data_unused > 1000:
print "美滋滋!有流量看小猪佩奇啦".decode('utf-8')
raw_input()
else:
print "额,没流量刷网页啦".decode('utf-8')
raw_input()
else:
print "请检查网络连接情况".decode('utf-8')
else:
print "请检查MAC地址".decode('utf-8')
if __name__ == '__main__':
output()