-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
executable file
·50 lines (39 loc) · 1.03 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
import dhcpreg
import json
from pprint import pprint
menu="""1 > View registered users
2 > Register new user
3 > Deregister user via MAC
4 > Look up MACs registerd under a nick
q > quit"""
while True:
print menu
try:
choice = raw_input(">> ")
if choice == "q": break
choice = int(choice)
except ValueError:
continue
print
if choice==2:
name = raw_input("Username: ")
mac = raw_input("Mac Address: ")
print dhcpreg.RegisterMac(mac,name)
if choice==1:
f=open("registrations.config")
pprint(json.load(f))
f.close()
if choice==3:
mac = raw_input("Mac Address: ")
name = dhcpreg.LookupMac(mac)
if name:
print("Removing user: {}".format(name))
dhcpreg.DeregisterMac(mac,name)
else:
print("Error: User not found.")
if choice == 4:
name = raw_input("Username: ")
pprint(dhcpreg.LookupNick(name))
# Print out a nice newline
print