File tree Expand file tree Collapse file tree 1 file changed +0
-41
lines changed
Expand file tree Collapse file tree 1 file changed +0
-41
lines changed Original file line number Diff line number Diff line change 11import functools
2- import ipaddress
32import json
43import logging
54import os
@@ -110,46 +109,6 @@ def get_architecture():
110109 return arch
111110
112111
113- def generate_ipv4_addr (subnet ):
114- """
115- Generate a valid random IPv4 address within the given subnet.
116-
117- :param subnet: Subnet in CIDR notation (e.g., '100.0.0.0/8')
118- :return: Random IP address within the subnet
119- """
120- reserved_ips = [
121- "0.0.0.0/8" ,
122- "10.0.0.0/8" ,
123- "100.64.0.0/10" ,
124- "127.0.0.0/8" ,
125- "169.254.0.0/16" ,
126- "172.16.0.0/12" ,
127- "192.0.0.0/24" ,
128- "192.0.2.0/24" ,
129- "192.88.99.0/24" ,
130- "192.168.0.0/16" ,
131- "198.18.0.0/15" ,
132- "198.51.100.0/24" ,
133- "203.0.113.0/24" ,
134- "224.0.0.0/4" ,
135- ]
136-
137- def is_public (ip ):
138- for reserved in reserved_ips :
139- if ipaddress .ip_address (ip ) in ipaddress .ip_network (reserved , strict = False ):
140- return False
141- return True
142-
143- network = ipaddress .ip_network (subnet , strict = False )
144-
145- # Generate a random IP within the subnet range
146- while True :
147- ip_int = random .randint (int (network .network_address ), int (network .broadcast_address ))
148- ip_str = str (ipaddress .ip_address (ip_int ))
149- if is_public (ip_str ):
150- return ip_str
151-
152-
153112def sanitize_tc_netem_command (command : str ) -> bool :
154113 """
155114 Sanitize the tc-netem command to ensure it's valid and safe to execute, as we run it as root on a container.
You can’t perform that action at this time.
0 commit comments