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:

208.183.71.73
220.227.153.121
139.184.93.247
23.11.185.207
253.181.185.173
65.177.198.161
134.64.137.29
202.87.227.133
123.65.54.241
23.180.96.86


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