-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
83 lines (55 loc) · 2.01 KB
/
main.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
#! /usr/local/bin/python3
import requests
from bs4 import BeautifulSoup
import hashlib
def generate_sid(key):
page = requests.get("http://fritz.box/login_sid.lua")
soup = BeautifulSoup(page.text, 'html.parser')
challenge_value = soup.find('challenge').text
password = challenge_value + '-' + key
md5_value = hashlib.md5(password.encode('utf-16le')).hexdigest()
page = requests.get("http://fritz.box/login_sid.lua?user=&response="
+ challenge_value + "-" + md5_value)
soup = BeautifulSoup(page.text, 'html.parser')
sidvalue = soup.find('sid').text
return sidvalue
def generate_lua(sidvalue):
wlan_page = requests.get("http://fritz.box/?sid=" + sidvalue + "&lp=netDev")
wlan_soup = BeautifulSoup(wlan_page.text, 'html.parser')
return ".lua?sid="+sidvalue
def currently_active_devices(sid):
"""
Receives a LUA_ID as input. Returns a list of all devices that are
currently connected to the network
"""
page = requests.request(method="GET", url="http://fritz.box/?sid=" + sid + "&lp=overview")
soup = BeautifulSoup(page.text, 'html.parser')
row = soup.findAll({'class': 'network list active no_column'})
for item in row:
print(item)
def wlan_connected(sid):
"""
Receives a LUA-ID as input. Returns a list of all devices ever
connected.
Parameters
----------
sid : String
Session ID Number, needed for every request.
"""
list = []
wifiSettingsURL = "http://fritz.box/wlan/wlan_settings" + sid
wifiPage = requests.get(wifiSettingsURL)
soup = BeautifulSoup(wifiPage.text, 'html.parser')
row = soup.findAll('td', {'class': 'cut_overflow name'})
for item in row:
list.add(item['title'])
def main():
print("Please enter Passphrase for FritzBox Webinterface:")
key = input()
sid = generate_sid(key)
lua = generate_lua(sid)
wlan_connected(lua)
# currently_active_devices(sid)
return 0
if __name__ == "__main__":
main()