Skip to content

Commit

Permalink
Updated Show DHCPINFO - Display
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Aug 31, 2017
1 parent bde20e9 commit cb3c198
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ptcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import configobj


ptcl = Router(password='ptcl')
# ptcl = Router(password='ptcl')
my_macs = {"mytab": "5c:2e:59:4d:33:67",
"ahmer": "68:94:23:AC:59:51",
"asad": "A0:32:99:AB:33:31",
"hhp": "44-1C-A8-73-A3-17",
"haris": "64:5A:04:76:C7:9C"
}
# ptcl = Router(mask='192.168.10.1', password='123motorcross')
ptcl = Router(mask='192.168.10.1', password='123motorcross')
# Defining custom aliases
# config['User-Aliases'] = {
# "mytab": "5c:2e:59:4d:33:67",
Expand Down
11 changes: 5 additions & 6 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import bs4
import re
import sys

from tabulate import tabulate

class Router(object):
'''
Expand Down Expand Up @@ -41,6 +41,8 @@ def scrape_page(self, url):
'''
try:
request_url = self.session.get(url)
if request_url.status_code == 401:
sys.exit("Username or Password is incorrect.")
html_soup = bs4.BeautifulSoup(request_url.content, 'html.parser')
return request_url, html_soup
except requests.exceptions.ConnectionError:
Expand Down Expand Up @@ -82,11 +84,8 @@ def show_dhcpinfo(self):
Shows DHCP information.
'''
self.get_dhcpinfo()
print "-" * 20 + "DHCP-INFO" + "-" * 20 + '\n'
for num, i in enumerate(zip(self.dev_hostname, self.mac_address), 1):
whitespace = 30 - len(i[0]) - len(str(num))
print "(%s) %s:%s\n" % (num, i[0], ' ' * whitespace + i[1].upper())
print "-" * 49
print tabulate({"HOSTNAME": self.dev_hostname, "MAC-ADDRESSES": self.mac_address}, headers=['HOSTNAME', 'Device-No.', 'MAC-ADDRESSES'], tablefmt='fancy_grid')
print "\n\n\t\tTotal Active Devices are [%s].\n\n" % len(self.dev_hostname)


def get_stationinfo(self):
Expand Down

0 comments on commit cb3c198

Please sign in to comment.