Python randomly generated IP address as string
>>> import random
>>> import socket
>>> import struct
>>> socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
'197.38.59.143'
>>> socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
'228.237.175.64'
NOTE This could generate IPs like 0.0.0.0
, 255.255.255.255
.
If you just want a string:
import random
ip = ".".join(map(str, (random.randint(0, 255)
for _ in range(4))))