-
Notifications
You must be signed in to change notification settings - Fork 0
/
re2o.py
44 lines (34 loc) · 1.34 KB
/
re2o.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
# encoding=utf8
import socket
import requests
from config import Config
CONFIG = Config()
username = CONFIG['Default']['USERNAME']
password = CONFIG['Default']['PASSWORD']
class Re2o:
def __init__(self):
self.session = requests.session()
self.errors = []
self.csrftoken = None
def get_csrf_token(self, url):
self.session.get(url)
self.csrftoken = self.session.cookies['csrftoken']
def init_connection(self):
try:
login_url = CONFIG.get_url('login')
self.get_csrf_token(login_url)
self.login_data = {'username': username, 'password': password, 'csrfmiddlewaretoken': self.csrftoken}
self.resp_co = self.session.post(login_url, data=self.login_data, headers=dict(referer=login_url))
except Exception as err:
self.errors.append(err)
print(self.errors) # TODO Handle errors
return
def check_mac(self, mac_search):
try:
mac_search = mac_search.lower()
mac_ip_dns = self.session.post(CONFIG.get_rest_url('mac-ip-dns'))
mac_ip_dns.raise_for_status()
mac_list = mac_ip_dns.json() # type: list
return len(list(filter(lambda mac: mac['mac_address'].lower() == mac_search, mac_list))) >= 1
except Exception as err:
print(err) # TODO