#!/usr/bin/perl
# This script asks for the subnet (in this case, it is the first 3 parts
# of the IP address), and appends every possible IP address from this subnet
# to /etc/hosts.  Must be run as root.

print "Subnet: ";
$subnet = <>;
chomp $subnet;

# This will create the new lines, each one in the following format:
# <full ip address>	Client-<ip>.rebel.com	Client-<ip>
# Where <ip> is a number from 1 to 254 (the last number of the full ip address)

open (FILE, "+>>/etc/hosts");
for ($i = 1; $i <255; $i++) {
 $address = $subnet . $i;
 print "$address	";
 print FILE "$address	";
 $address2 = "Client-" . $i;
 $name = $address2 . ".rebel.com" . " $address2";
 print FILE "$name\n";
}

close FILE;

