From 2ce04db709425d9dd8aa701b250a8af688735cdd Mon Sep 17 00:00:00 2001 From: Rafay Ghafoor Date: Sat, 2 Sep 2017 01:07:08 +0500 Subject: [PATCH 1/2] Fixed config --- configure.py | 15 +++++++++++++++ ptcl.py | 25 +++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/configure.py b/configure.py index 60b00b3..ffea993 100644 --- a/configure.py +++ b/configure.py @@ -1,6 +1,7 @@ import configobj import os +config = "" def write_config(): # Creating a config file @@ -56,7 +57,21 @@ def set_alias(): else: print "Already Present." + def get_alias(): # Return Aliases config = configobj.ConfigObj('config.ini') return config["Aliases"] + + +def config_check(): + path = os.path.expanduser(os.path.join('~', '.config' + os.sep + 'ptcl')) + + if os.path.exists(path): + os.chdir(path) + global config + config = configobj.ConfigObj('config.ini') + return True + else: + write_config() + return False diff --git a/ptcl.py b/ptcl.py index 1ac0b2c..6b2b2da 100755 --- a/ptcl.py +++ b/ptcl.py @@ -6,18 +6,6 @@ import os from tabulate import tabulate -path = os.path.expanduser(os.path.join('~', '.config' + os.sep + 'ptcl')) - -if os.path.exists(path): - os.chdir(path) - config = configobj.ConfigObj('config.ini') - ptcl = Router(mask=config["Router-Auth"]["mask"], password=config["Router-Auth"]["password"]) - -else: - print "Configuration file doesn't exists. Run it with --configure parameter.\nExecuting Fallback mode." - ptcl = Router(mask="192.168.10.1", password="123motorcross") - # ptcl = Router(password='ptcl') - def show_dhcpinfo(): ''' @@ -78,7 +66,15 @@ def main(): parser.add_argument('-sa', '--set-alias', help='Set custom alias for a device hostname.', action='store_true') parser.add_argument('-c', '--cli', help='Silent mode.', nargs='?', default='False') args = parser.parse_args() - # print args + + if configure.config_check() == True: + if configure.config: + global ptcl + ptcl = Router(mask=configure.config["Router-Auth"]["mask"], password=configure.config["Router-Auth"]["password"]) + + else: + configure.config_check() + sys.exit("Please Re-run.") if args.cli == 'False': my_macs = configure.get_alias() @@ -118,9 +114,6 @@ def main(): elif args.blocked_dev: show_blocked_dev() - elif args.configure: - configure.write_config() - elif args.set_alias: show_active_dev() configure.set_alias() From 9da036af1c25e128584b7ee56c5d6e3c3ec042f9 Mon Sep 17 00:00:00 2001 From: Rafay Ghafoor Date: Sat, 2 Sep 2017 01:08:08 +0500 Subject: [PATCH 2/2] Updated --- README.md | 113 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index f3f3c18..06685ab 100755 --- a/README.md +++ b/README.md @@ -1,70 +1,99 @@ -# PTCL-Router: +# PTCL-Router-API: -A PTCL-Router API. +A PTCL-Router API to interact with default router interface. -# Current-Features: +# Usage: -- 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: ptcl.py [-h] [-b [BLOCK]] [-sb] [-u [UNBLOCK]] [-a] [-r] [-sd] + [-s SHOW_ACTIVE] [-c] [-q [QUIET]] -# Usage: +Control PTCL router from command-line. -**Shows devices connected to the router.** +Options: -```python ->>> python ptcl.py + -h, --help show this help message and exit + + -b [BLOCK], --block [BLOCK] + Block device. + + -sb, --blocked_dev Display blocked devices. + + -u [UNBLOCK], --unblock [UNBLOCK] + Unblock device. + + -a, --active-devices Gets number of devices connected to the router. + + -r, --restart Restart Router. + + -sd, --show-dhcp Show DHCP Info. + + -s SHOW_ACTIVE, --show-active SHOW_ACTIVE + Show Active Devices. + + --configure Configure router settings. + + -c [CLI], --cli [CLI] + CLI mode (used in conjunction with -u or -b). ``` -**Shows currently active devices and provides an option to block device from the display.** +# Examples: -```python ->>> python ptcl.py -b ``` +>>> python ptcl.py --configure # Configure router gateway, username and password -**Shows DHCP info for all devices connected in a day.** +>>> python ptcl.py # Shows currently active devices. -```python ->>> python ptcl.py -sd -``` +>>> python ptcl.py -sa # Set custom aliases for mac addresses. + +>>> python ptcl.py -b USER # Block user from custom defined alias. + +>>> python ptcl.py -ub USER # Unblock user from custom defined alias. + +>>> python ptcl.py -b -c # Block devices from the active devices display. + +>>> python ptcl.py -sb # Show blocked users. -**Reboots the router.** +>>> python ptcl.py -sd # Show DHCP info. -```python ->>> python ptcl.py -r +>>> python ptcl.py -r # Reboots router. ``` +# 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) ). + # TODO: -- [ ] Writing documentation for API usage. -- [ ] Organizing TODO in sections. +- [X] Writing documentation for API usage. - [ ] Port-Forwarding from command line. - [ ] Parsing router logs. +- [X] Display number of active devices. +- [X] Optimize Regular Expressions. - [ ] Obtaining Pin-Code of the router and changing it. - [ ] Displaying current password of the SSID. +- [X] Setting up custom hostname for specific device (mac address). - [ ] Changing router username and password from the command-line. -- [ ] Changing SSID-Name. -- [ ] Adding a method to change router password. -- [ ] Add CLI MODE for unblocking devices. +- [ ] Changing Router SSID-Name. +- [X] Add CLI MODE for unblocking devices. - [ ] Option to change frequency 2.4 Ghz or 5 Ghz. +- [X] Testing on other routers from the same vendor. - [ ] Option to change router transmission power. -- [ ] Improving display for blocked devices. -- [ ] Exclude android devices from station info and dhcp info (Optional). +- [X] Improving display for blocked devices. - [ ] 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 cloud everyday. -- [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. +- [ ] Getting devices connection info in a nice CSV file. +- [X] CLI MODE and SILENT MODE for blocking devices. + + + + +