-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
51 lines (36 loc) · 1.4 KB
/
server.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
51
#!/usr/bin/env python2.7
from pydhcplib.dhcp_packet import *
from pydhcplib.dhcp_network import *
netopt = {'client_listen_port':"68",
'server_listen_port':"67",
'listen_address':"0.0.0.0"}
goodservers_str = [ '192.168.251.2', '192.168.251.3' ]
goodservers = [ [ int(n) for n in s.split('.') ] for s in goodservers_str ]
class Server(DhcpServer):
def __init__(self, options):
DhcpServer.__init__(self,options["listen_address"],
options["client_listen_port"],
options["server_listen_port"])
def HandleDhcpDiscover(self, packet):
pass
def HandleDhcpRequest(self, packet):
server_identifier = packet.GetOption('server_identifier')
if server_identifier is not None:
if server_identifier != []:
if server_identifier not in goodservers:
with open('badpackets.txt','a') as f:
f.write(packet.str())
f.write('-----------------------------------------------------\n\n')
print packet.str()
def HandleDhcpDecline(self, packet):
pass
def HandleDhcpRelease(self, packet):
pass
def HandleDhcpInform(self, packet):
pass
def main():
server = Server(netopt)
while True :
server.GetNextDhcpPacket()
if __name__ == "__main__":
main()