Tuesday, April 15, 2014

Perl Script: finding free IP addresses on a C-class network

I need 10 IP addresses in a row for the new webster, preferably - don't worry i haven't stolen any yet .. but there are ten in a row from 167.123.1.240
to 167.123.1.249

but this simple one liner can be used to determine what is available

wal:/ # perl -e 'foreach $i ( 1 .. 255 ) { $x=qx{ping 167.123.1.$i 1}; print $x if ($x =~ m!no answer!sig)}'
no answer from 167.123.1.12
no answer from 167.123.1.16
no answer from 167.123.1.21
no answer from 167.123.1.22
no answer from 167.123.1.24
no answer from 167.123.1.28
no answer from 167.123.1.29
no answer from 167.123.1.30
no answer from 167.123.1.31
no answer from 167.123.1.34
no answer from 167.123.1.36
no answer from 167.123.1.37
no answer from 167.123.1.38
no answer from 167.123.1.41
no answer from 167.123.1.42
no answer from 167.123.1.43
no answer from 167.123.1.44
no answer from 167.123.1.45
no answer from 167.123.1.46
no answer from 167.123.1.47
no answer from 167.123.1.49
no answer from 167.123.1.50
no answer from 167.123.1.53


etc...

No comments:

Post a Comment