This repository was archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm3connect
executable file
·93 lines (74 loc) · 2.27 KB
/
m3connect
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
#!/usr/bin/env python3
import requests
import json
import sys
login = None
password = None
if not all([login, password]):
print("Enter login/password in script above")
sys.exit(1)
def enable_debug():
import logging
import http.client as http_client
http_client.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
enable_debug()
def get_token_from_html_page(html_page_as_text):
start_search = 'conn4.hotspot.wbsToken = {"token":"'
end_search = '"'
start_token_index = html_page_as_text.index(start_search) + len(start_search)
program_ab_start_token_index = html_page_as_text[start_token_index:]
end_token_index = program_ab_start_token_index.index(end_search)
tkn = program_ab_start_token_index[:end_token_index].replace('\\', '')
print(tkn)
return tkn
sess = requests.Session()
get_portal_request = sess.get("http://neverssl.com", allow_redirects=False)
try:
portal_url = get_portal_request.headers['Location']
except KeyError:
print("Already logged in!")
sys.exit(0)
portal_request = sess.get(portal_url, allow_redirects=False)
portal_redir = portal_request.headers['Location']
print(portal_request.url)
print(portal_request.status_code)
print()
drei = sess.get(portal_redir, allow_redirects=False)
drei_url = drei.headers['Location']
print(drei.url)
print(drei.status_code)
print()
f = sess.get(drei_url)
base_url = f.url # die seite mit / am ende
sessionid = sess.cookies['PHPSESSID']
token = get_token_from_html_page(f.text)
print(f.url)
print(f.status_code)
print()
a = sess.post(base_url + 'wbs/api/v1/create-session/', data={
"session_id": sessionid,
"with-tariffs": 1,
"locale": "de_DE",
"authorization": "token=" + token,
})
create_session_session = json.loads(a.text).get('session')
print(a.url)
print(a.status_code)
print(sess.cookies)
print(a.text)
print()
b = sess.post(base_url + 'wbs/api/v1/login/voucher/', data={
"authorization": "session=" + create_session_session,
"login[username]": login,
"login[password]": password,
})
print(b.url)
print(b.status_code)
print(sess.cookies)
print(b.text)
print()