Small fixes with dhcptest.py
This commit is contained in:
parent
80f6837d72
commit
4e24bd0f63
1 changed files with 8 additions and 8 deletions
16
dhcptest.py
16
dhcptest.py
|
@ -39,7 +39,7 @@ class DHCPPack:
|
||||||
self.file = ""
|
self.file = ""
|
||||||
|
|
||||||
def pack(self):
|
def pack(self):
|
||||||
return struct.unpack(DHCPPack.fmt,
|
return struct.pack(DHCPPack.fmt,
|
||||||
self.op,
|
self.op,
|
||||||
self.htype,
|
self.htype,
|
||||||
self.hlen,
|
self.hlen,
|
||||||
|
@ -71,19 +71,19 @@ class DHCPPack:
|
||||||
self.chaddr[5],
|
self.chaddr[5],
|
||||||
self.chaddr[6],
|
self.chaddr[6],
|
||||||
self.chaddr[7],
|
self.chaddr[7],
|
||||||
self.sname,
|
str.encode(self.sname),
|
||||||
self.file)
|
str.encode(self.file))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
s.bind(('',68))
|
s.bind(('',67))
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
#s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||||
|
|
||||||
packet = DHCPPack();
|
#packet = DHCPPack();
|
||||||
s.sendto(packet.pack(), ('<broadcast>',67))
|
#s.sendto(packet.pack(), ('<broadcast>',67))
|
||||||
|
|
||||||
data, addr = sock.recvfrom(1024)
|
data, addr = s.recvfrom(1024)
|
||||||
|
|
||||||
packet2 = DHCPPack(data)
|
packet2 = DHCPPack(data)
|
||||||
if packet2.op == 2:
|
if packet2.op == 2:
|
||||||
|
|
Loading…
Reference in a new issue