Skip to content

Commit 325ff00

Browse files
committed
util: remove ipv4 generator
1 parent 14cf126 commit 325ff00

File tree

1 file changed

+0
-41
lines changed

1 file changed

+0
-41
lines changed

src/warnet/utils.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import functools
2-
import ipaddress
32
import json
43
import logging
54
import 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-
153112
def 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.

0 commit comments

Comments
 (0)