Jump to content
wind

Perl Hostname Generator for linux

Recommended Posts

Posted
#!/usr/bin/perl
########################################
#Perl Random Hostname Generator
#
# Files Modified:
# /etc/hostname
# /proc/sys/kernel/hostname
#
# A SoldierX utility by EverestX
########################################


print "****Hostname Generator****\n";
print " A SoldierX Utility\n\n";



if ($#ARGV !=) {

#This Section generates a 5 char alphanumeric value
$host = rand_host();



sub rand_host {

my @chars = ('a'..'z','0'..'9');

my $len = 4;

$host = '';

for (..$len) {

$host .= $chars[int rand @chars];

}



# This Section generates the 1st Letter


$letter = rand_letter();

sub rand_letter{

my @chars = ( 'A'..'Z');

my $length = ;

$letter = '';

for (..$length){

$letter .= $chars[int rand @chars];

}

#Combine the 1st letter & other 5 digits.

$hostname = $letter.$host;

print " Random hostname set to: $hostname \n";


#Change the host files

open (FILE1, '>/etc/hostname');
print FILE1 "$hostname";
close (FILE1);


open (FILE2, '>/proc/sys/kernel/hostname');
print FILE2 "$hostname";
close (FILE2);

}

}
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...