Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Jul 21, 2017
1 parent f627767 commit 0be0f27
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
18 changes: 9 additions & 9 deletions ptcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ def main():
args = parser.parse_args()

if args.block:
ptcl.show_active_dev()
dev_mac = raw_input("Please Enter Device Mac Address: ").upper()
ptcl.block_dev(dev_mac, get_sessionkey())
name = ptcl.show_active_dev()
dev_mac = int(raw_input("Please Enter Device Number: ")) - 1
ptcl.block_dev(ptcl.mac_and_host[name[dev_mac]], ptcl.get_sessionkey())

elif args.unblock:
ptcl.show_active_dev()
udev_mac = raw_input("Please Enter Device Mac Address: ").upper()
ptcl.unblock_dev(udev_mac, get_sessionkey())
udev_mac = raw_input("Please Enter Device Number: ").upper()
ptcl.unblock_dev(ptcl.mac_and_host[name[udev_mac]], ptcl.get_sessionkey())

elif args.restart:
ptcl.reboot_router(get_sessionkey())
ptcl.reboot_router(ptcl.get_sessionkey())

elif args.show_dhcp:
ptcl.show_dhcpinfo()

elif args.show_active:
ptcl.show_active_dev()

elif args.show_dhcp == '.':
ptcl.show_dhcpinfo()

else:
print "Invalid Argument"

Expand Down
60 changes: 37 additions & 23 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
>>> from routerPTCL import Router
>>> router = Router('192.168.1.1')
>>> router.login() # Logs in to the router
>>> router.reboot() # Reboots router
>>> router.self.active_dev() # Shows devices which are currently connected to the router
>>> router.active_dev() # Shows devices which are currently connected to the router
'''

import requests
Expand All @@ -21,7 +20,6 @@ class Router(object):
'''
A PTCL router class.
'''
hostname_regex = re.compile(r"\w{3,10}")
macAddress_regex = re.compile(r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$')


Expand Down Expand Up @@ -53,6 +51,14 @@ def get_dhcpinfo(self):
# print "%r" %i
for i in td:
if self.macAddress_regex.search(i.text):
'''
The HTML page contains hostnames and mac addresses right next
to each other in the form of table. We search in the tables list
(td) until a mac address is found, then appends it to the
mac_address list. The hostname is located before it so by using
index less than the current index of mac address, we obtain the
hostname and append it to the dev_hostname list.
'''
self.dev_hostname.append(td[td.index(i) - 1].text.encode('ascii'))
self.mac_address.append(i.text.encode('ascii'))

Expand All @@ -68,8 +74,11 @@ def get_dhcpinfo(self):

def show_dhcpinfo(self):
self.get_dhcpinfo()
for i in zip(self.mac_address, self.dev_hostname):
print "%s: %s" % (i[0].upper(), i[1].lower().capitalize())
print "-" * 20 + "DHCP-INFO" + "-" * 20 + '\n'
for num, i in enumerate(zip(self.dev_hostname, self.mac_address), 1):
whitespace = 30 - len(i[0])
print "%s:%s\n" % (i[0], ' ' * whitespace + i[1].upper())
print "-" * 49


def get_stationinfo(self):
Expand All @@ -85,14 +94,18 @@ def show_active_dev(self):
'''Shows active devices (Mac Addresses) and their hostnames'''
self.get_stationinfo()
self.get_dhcpinfo()
mac_host = dict(zip(self.dev_hostname, self.mac_address))
self.mac_and_host = dict(zip(self.dev_hostname, self.mac_address))
hostnames = []
print "-" * 20 + "STATION-INFO" + "-" * 20 + '\n'
for k, v in mac_host.iteritems():
for i, active_clients in enumerate(self.active_dev):
count = 1
for k, v in self.mac_and_host.iteritems():
for active_clients in self.active_dev:
if active_clients in v:
print "(%s) %s%s\n" % (i, k + ":" + ' ' * (30 - len(k)), active_clients.upper())
print "(%s) %s%s\n" % (count, k + ":" + ' ' * (30 - len(k)), active_clients.upper())
hostnames.append(k)
count += 1
print "-" * 52 + '\n'

return hostnames


def get_sessionkey(self):
Expand Down Expand Up @@ -139,6 +152,20 @@ def url_remove_filter(self):
pass


class Monitor(Router):
'''
Monitor class derived from the router, which contains method for
monitoring users connected to router.
'''

def get_suspects(self):
'''
Searches suspected users who are currently connected
to the router.
'''
suspects = {"User 1": "Mac_Address"} # Sample


def monitor_dev(self): # Monitor Devices
'''Monitor devices, when they connect to router and disconnect. Also
gets the time a device remains connected to the router.'''
Expand All @@ -149,16 +176,3 @@ def dev_conninfo(self): # Device Connection Info
'''Analyzes how much time a device remains connected to the device throughout
the day.'''
pass


def login(self):
'''Logs into the router.'''
pass


def get_suspects(self):
'''
Searches suspected users who are currently connected
to the router.
'''
suspects = {"User 1": "Mac_Address"}

0 comments on commit 0be0f27

Please sign in to comment.