Make a random IP address in Perl

This Perl script makes reasonably convincing random IPv4 internet addresses.

#!/home/ben/software/install/bin/perl
use warnings;
use strict;
sub randomip
{
    my @digits;
    for (0..3) {
        push @digits, int (rand (255) + 1);
    }
    return join '.', @digits;
}
for (0..9) {
    print randomip (), "\n";
}

(download)

The output looks like this:

107.50.10.111
91.31.44.18
88.192.136.231
30.174.240.63
185.187.178.229
229.164.72.213
33.146.159.32
206.48.29.252
160.181.20.5
227.178.162.105

(download)


Copyright © Ben Bullock 2009-2021. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. News about the site. / Privacy / Disclaimer