39
39
StrField ,
40
40
StrFixedLenField ,
41
41
XIntField ,
42
+ RawVal
42
43
)
43
44
from scapy .layers .inet import UDP , IP
44
45
from scapy .layers .l2 import Ether , HARDWARE_TYPES
@@ -669,6 +670,24 @@ def make_reply(self, req):
669
670
class DHCP_am (BOOTP_am ):
670
671
function_name = "dhcpd"
671
672
673
+ def ip_to_bytes (self , ip_string ):
674
+ """Concat a IP str of form IP,IP,IP and returns it as bytes
675
+ Backcompatible if IP is a single IP.
676
+ :param ip_string: String of the IP to be packed"""
677
+ ip_string = ip_string .replace (" " , "" )
678
+
679
+ # Split IPs by commas and filter out empty strings
680
+ ip_list = [ip .strip () for ip in ip_string .split (',' ) if ip .strip ()]
681
+
682
+ # Convert each IP to packed format
683
+ packed_ips = []
684
+ for ip in ip_list :
685
+ packed_ips .append (socket .inet_aton (ip ))
686
+
687
+ # Concatenate packed IPs into a single byte string
688
+ return b'' .join (packed_ips )
689
+
690
+
672
691
def make_reply (self , req ):
673
692
resp = BOOTP_am .make_reply (self , req )
674
693
if DHCP in req :
@@ -677,12 +696,15 @@ def make_reply(self, req):
677
696
for op in req [DHCP ].options
678
697
if isinstance (op , tuple ) and op [0 ] == "message-type"
679
698
]
699
+
700
+ nameserver_list = self .ip_to_bytes (self .nameserver )
701
+
680
702
dhcp_options += [
681
703
x for x in [
682
704
("server_id" , self .gw ),
683
705
("domain" , self .domain ),
684
706
("router" , self .gw ),
685
- ("name_server" , self . nameserver ),
707
+ ("name_server" , IP ( len = RawVal ( nameserver_list )) ),
686
708
("broadcast_address" , self .broadcast ),
687
709
("subnet_mask" , self .netmask ),
688
710
("renewal_time" , self .renewal_time ),
0 commit comments