A Random IP Generator generates IP addresses randomly. An IP address, short for Internet Protocol address, is a numerical label assigned to each device connected to a computer network. This generator provides a quick way to create a variety of IP addresses for various testing and development purposes.
import random
def generate_random_ip():
octets = [str(random.randint(0, 255)) for _ in range(4)]
ip_address = ‘.’.join(octets)
if is_valid_ip(ip_address):
return ip_address
else:
return generate_random_ip()
def is_valid_ip(ip):
octets = ip.split(‘.’)
if len(octets) != 4:
return False
for octet in octets:
if not octet.isdigit() or not 0 <= int(octet) <= 255:
return False
return True
print(generate_random_ip())