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:

39.186.218.74
61.30.148.207
148.42.236.164
123.37.217.254
192.83.193.84
234.4.146.81
162.161.223.13
28.137.217.104
134.64.122.211
161.238.103.90

(download)


Copyright © Ben Bullock 2009-2019. 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