Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the shortest way to generate a random IP address in Ruby?

Just like the title says, wanted for testing purposes.

like image 785
Ben Crouse Avatar asked May 11 '10 04:05

Ben Crouse


People also ask

Can I randomize my IP address?

Use a VPN They hide your IP by providing you with access to their network of servers. Whenever you connect to one of these servers, which are located all over the world, your real IP address gets hidden, and you are assigned a new one that is tied to the server you are connected to.


1 Answers

You could use IPAddr

require 'ipaddr'
ipv4 = IPAddr.new(rand(2**32),Socket::AF_INET)
ipv6 = IPAddr.new(rand(2**128),Socket::AF_INET6)
like image 52
Aaron Lee Avatar answered Oct 06 '22 11:10

Aaron Lee