-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
188 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import configobj | ||
import os | ||
|
||
|
||
def write_config(): | ||
# Creating a config file | ||
try: | ||
os.chdir(os.path.expanduser(os.path.join('~', ''))) | ||
os.makedirs('.config' + os.sep + "ptcl") | ||
os.chdir('.config' + os.sep + "ptcl") | ||
|
||
except OSError: | ||
# If already exists | ||
pass | ||
|
||
config = configobj.ConfigObj() | ||
DEFAULT = {'mask': '192.168.1.1', 'username': 'admin', 'password': 'admin'} | ||
mask = raw_input("Leave empty for default configuration.\nPlease enter router gateway\t(Default 192.168.1.1)\t: ") | ||
|
||
if mask: | ||
DEFAULT['mask'] = mask | ||
username = raw_input("Please enter router username\t(Default admin)\t: ") | ||
|
||
if username: | ||
DEFAULT['username'] = username | ||
password = raw_input("Please enter router password\t(Default admin)\t: ") | ||
|
||
if password: | ||
DEFAULT['password'] = password | ||
config['Router-Auth'] = DEFAULT | ||
config['Aliases'] = {} | ||
|
||
with open('config.ini', 'w') as configfile: | ||
config.write(configfile) | ||
print '\nConfiguration file Generated.' | ||
|
||
|
||
def set_alias(): | ||
# Defining custom aliases | ||
config = configobj.ConfigObj('config.ini') | ||
|
||
while True: | ||
hostname = raw_input("Set Alias for hosname: ") | ||
if hostname == 'q': | ||
break | ||
macaddress= raw_input("Enter it\'s macaddress: ") | ||
|
||
if macaddress == 'q': | ||
break | ||
|
||
else: | ||
if hostname not in config["Aliases"]: | ||
config["Aliases"][hostname] = macaddress | ||
with open('config.ini', 'r+') as configfile: | ||
config.write(configfile) | ||
else: | ||
print "Already Present." | ||
|
||
def get_alias(): | ||
# Return Aliases | ||
config = configobj.ConfigObj('config.ini') | ||
return config["Aliases"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.