Just like the title says, wanted for testing purposes.
Thanks!
Just like the title says, wanted for testing purposes.
Thanks!
If you want a truly random IP address, Array.new(4){rand(256)}.join('.')
does it
I've used this before to generate a random ip then validate it with Resolv
ip = "#{rand(99)}.#{rand(100)}.#{rand(10)}.#{rand(255)}"
begin
if ip
host = Resolv.new.getname(ip)
puts "#{c} #{real_ip.length} #{ip} #{host}"
end
rescue Exception => e
puts "FAKE #{ip}"
end
You could use IPAddr
require 'ipaddr'
ipv4 = IPAddr.new(rand(2**32),Socket::AF_INET)
ipv6 = IPAddr.new(rand(2**128),Socket::AF_INET6)