Skip to content

Commit

Permalink
Fixed arguments parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafay Ghafoor committed Aug 8, 2017
1 parent 3153472 commit d8cc64b
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 23 deletions.
72 changes: 70 additions & 2 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,74 @@
# PTCL-Router-Configure:
# PTCL-Router:

A PTCL-Router API.

# Current-Features:

- Obtain station information, showing their hostnames alongside for better readability (devices currently connected to the router).
- Obtain DHCP information.
- Block and unblock devices using their mac addresses.
- Block and unblock devices using their predefined aliases.
- Reboot router.
- Over-ride hostnames associated to the mac address with custom hostnames.
- Display blocked devices.
- Added two modes for blocking users ( CLI-MODE and SILENT-MODE (Default) ).

# Usage:

**Shows devices connected to the router.**

```python
>>> python ptcl.py
```

**Shows currently active devices and provides an option to block device from the display.**

```python
>>> python ptcl.py -b
```

**Shows DHCP info for all devices connected in a day.**

```python
>>> python ptcl.py -sd
```

**Reboots the router.**

```python
>>> python ptcl.py -r
```

# TODO:

- [ ] Writing documentation for API usage.
- [ ] Organizing TODO in sections.
- [ ] Port-Forwarding from command line.
- [ ] Parsing router logs.
- [ ] Obtaining Pin-Code of the router and changing it.
- [ ] Displaying current password of the SSID.
- [ ] Changin router username and password from the command-line.
- [ ] Changing SSID-Name.
- [ ] Adding a method to change router password.
- [ ] Option to change frequency 2.4 Ghz or 5 Ghz.
- [ ] Option to change router transmission power.
- [ ] Improving display for blocked devices.
- [ ] Exclude android devices from station info and dhcp info.
- [ ] Time restriction for user (by specifying or choosing from station info) device mac address or hostname.
- [ ] Adding URL to block unnecessary use for a website, also time limit for a site usage.
- [ ] Monitor devices connection info i.e., when they connect to the router and disconnect. Also devices uptime of the day.
- [ ] Block devices who remain connected to the router for x time (6 hours). Unblock them after 6 hours.
- [ ] Searching suspected users in the station info (Currently Active Devices) when speed is slow.
- [ ] Getting device connection info in a nice CSV file.
- [ ] Uploading CSV on a cloud everyday.
- [ ] Add CLI MODE for unblocking devices
- [X] Setting up custom hostname for specific device (mac address).
- [X] Optimize Regular Expressions.
- [X] CLI MODE and SILENT MODE for blocking devices.
- [X] Testing on other routers from the same vendor.
- [X] Reboot router from script.
- [X] Display number of active devices.

Allows to configure and access options of PTCL router from commandline. Currently allows to get station info, dhcp info, block devices by mac addresses and unblock them.



Empty file modified TODO.md
100644 → 100755
Empty file.
Empty file modified numbering.py
100644 → 100755
Empty file.
24 changes: 14 additions & 10 deletions ptcl.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
def main():
parser = argparse.ArgumentParser(description="Control PTCL router from command-line.")
parser.add_argument('-b', '--block', help="Block device.", nargs='?')
parser.add_argument('-sb', '--blocked_dev', help='Quite mode.', action='store_true')
parser.add_argument('-u', '--unblock', help="Unblock device.", nargs='?')
parser.add_argument('-a', '--active-devices', help="Gets active devices number.", action='store_true')
parser.add_argument('-r', '--restart', help="Restart Router.", action='store_true')
Expand All @@ -32,10 +33,10 @@ def main():

if args.quiet == 'True':
if args.block:
print "Calling blocker Function"
# print "Calling blocker Function"
ptcl.get_sessionkey()
if args.block in my_macs.iterkeys():
print "Calling blocker function - AUTOMATED MODE."
# print "Calling blocker function - AUTOMATED MODE."
ptcl.block_dev(my_macs[args.block.lower()])
print "%s has been blocked." % args.block.capitalize()
if args.block not in my_macs.iterkeys():
Expand All @@ -46,46 +47,49 @@ def main():
elif args.unblock:
ptcl.get_sessionkey()
if args.unblock in my_macs.iterkeys():
print "Calling unblocker function - AUTOMATED MODE"
# print "Calling unblocker function - AUTOMATED MODE"
ptcl.unblock_dev(my_macs[args.unblock.lower()])
print "%s has been unblocked." % args.unblock.capitalize()
elif args.unblock not in my_macs.iterkeys():
print "User not found."

elif args.active_devices:
print "Calling Station info Function"
# print "Calling Station info Function"
ptcl.get_stationinfo()
print "Currently active devices are:", len(ptcl.active_dev)

elif args.restart:
print "Calling restart Function"
# print "Calling restart Function"
ptcl.get_sessionkey()
ptcl.reboot_router()

elif args.show_dhcp:
print "Calling DHCP_info Function"
# print "Calling DHCP_info Function"
# ptcl.get_sessionkey()
ptcl.show_dhcpinfo()

elif args.blocked_dev:
ptcl.show_blocked_dev()

elif args.show_active == '.':
print "Calling show_active Function"
# print "Calling show_active Function"
ptcl.show_active_dev()

else:
print "Invalid Argument"


elif not args.quiet:
if not args.block:
print "Calling blocker function - CLI MODE."
# print "Calling blocker function - CLI MODE."
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]])
print "%s has been blocked." % name[dev_mac].capitalize()


elif not args.unblock:
print "Calling unblocker function - CLI MODE."
# print "Calling unblocker function - CLI MODE."
name = ptcl.show_active_dev()
dev_mac = int(raw_input("Please Enter Device Number: ")) - 1
ptcl.unblock_dev(ptcl.mac_and_host[name[dev_mac]])
Expand Down
32 changes: 21 additions & 11 deletions router.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,35 @@ def unblock_dev(self, udevmac):


def show_blocked_dev(self):
pass


def set_hostname(self):
pass


def hh_to_HH(self, time):
'''
Converts 12 hours format to 24 hours.
Display blocked devices.
'''
pass
r, soup = self.scrape_page(self.mask + "wlmacflt.cmd?action=view")
print "Showing blocked devices.\n"
for i in soup.findAll('td'):
if not i.find("input"):
if Router.mac_adr_regex.search(i.text):
print i.text + '\n'


def set_hostname(self, custom_name, mac_address):
'''
Set custom hostname for a device. For example:
>>> DESKTOP-1RXG23 --> My-PC
'''
self.get_dhcpinfo()
custom_hostnames = {}
self.mac_and_host = dict(zip(self.dev_hostname, self.mac_address))
for i in self.mac_and_host.items():
if mac_address in i:
del(self.mac_and_host[i[0]])
self.mac_and_host[custom_name] = mac_address


def reboot_router(self):
'''
Reboots Router.
'''
self.get_stationinfo()
r, soup = self.scrape_page(self.mask + ("rebootinfo.cgi?sessionKey=%s") % self.session_key)
print "Rebooted."

Expand Down

0 comments on commit d8cc64b

Please sign in to comment.