Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Mar 25, 2018
1 parent 7d25d5a commit 35c4d45
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
{'HOSTNAME': ['Mac', 'LocalIp', 'Expires']}
{'my-computer': ['macxx', '192.168.10.1', '23 Hours, 59 Minutes']}
'''

import re
import sys

Expand All @@ -35,7 +34,7 @@ class Router():
mac_pattern = re.compile(u'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$')


def __init__(self, gateway="192.168.10.1", username="admin", password="admin"):
def __init__(self, gateway="192.168.1.1", username="admin", password="ptcl"):
self.gateway = "http://" + gateway + '/'
self.username = username
self.password = password
Expand Down Expand Up @@ -74,10 +73,10 @@ def get_session_key(self):
Gets session key from the html page for interacting with forms which
require session key for authentication.
'''
r = self.scrape_page(url=(self.gateway + "wlmacflt.cmd"))
r = self.scrape_page(url=self.gateway + 'wlmacflt.cmd')

if not self.sessionKey:
self.sessionKey = re.search('\d{3,30}', r.content.decode()).group()
self.sessionKey = re.search('\d{5,13}', r.content.decode()).group()

return self.sessionKey

Expand Down Expand Up @@ -112,7 +111,6 @@ def dhcpinfo(self):
# After mac_addresses, there are local ip and expire time for
# the devices connected
hostname = td[td.index(i) - 1].text
self.dev_info["Hostname"] = hostname
self.dev_info[hostname] = [i.text, td[td.index(i) + 1].text, td[td.index(i) + 2].text]

return self.dev_info
Expand Down Expand Up @@ -261,13 +259,3 @@ def reboot(self):
Reboots Router.
'''
self.session.get(self.gateway + "rebootinfo.cgi?sessionKey={}".format(self.get_session_key()))


if __name__ == '__main__':
papi = Router()

print(papi.get_session_key())

print(papi.stationinfo())

print(papi.dhcpinfo())

0 comments on commit 35c4d45

Please sign in to comment.