-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.py
77 lines (64 loc) · 2.13 KB
/
logger.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
import requests
import subprocess
headers = \
{'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'}
def login(uname, passw):
url_1 = 'http://www.google.com'
session = requests.Session()
res = session.get(url_1, headers=headers)
magic = res.url.split('?')[1]
url_2 = res.url
payload = {
'4Tredir': 'http://google.com/',
'username': uname,
'password': passw,
'magic': str(magic),
}
res = requests.post(url_2, headers=headers, data=payload)
# print res.text
if 'Failed' in res.text:
print(uname + 'failed')
return False
else:
print(uname + ':' + passw)
print(res.url)
return True
def main():
cmd = 'ip r | grep "default" | cut -d" " -f3'
ps = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = ps.communicate()[0]
ip_addr = output[:-1].decode("utf-8")
# print(ip_addr)
port = "1000"
print("Checking connectivity..")
try:
res = requests.head('http://www.google.co.in')
print('Already connected. :)')
requests.get(
url='http://'+ip_addr+':'+port+'/logout?0c0a0e0a0a1fea52', headers=headers)
print("Logged out successfully")
except requests.ConnectionError:
details = {'uname1' : 'passw1', 'uname2' : 'passwd2'}
for key in cache:
username = key
password = details[key]
if login(username, password):
# r = get(
# url="http://172.16.12.1:1000/logout?0c0a0e0a0a1fea52", headers=headers)
print("Logged in")
exit(0)
else:
pass
for key in details:
username = key
password = details[key]
if login(username, password):
# r = get(
# url="http://172.16.12.1:1000/logout?0c0a0e0a0a1fea52", headers=headers)
print("Logged in")
break
else:
pass
if __name__ == '__main__':
main()