Convert IPs to decimal and back

  Snippets, PERL snippets, Network

This is a simple script that interactively converts an IP address to its decimal equivalent. This can sometimes be used to bypass web content filtering devices as not all will convert the decimal to an IP and then a hostname.

 # prompt for an IP
 print "Enter an IP Address: ";
# get the users input
 $_ = ;
# remove the newline "n" character
# should validate the input, but this was a simple/quick program
 $converteddecimal = ip2dec($_);
 $convertedip = dec2ip($converteddecimal);
print "nIP address: $_n";
 print "Decimal: $converteddecimaln";
# print "IP: $convertedipn";
# this sub converts a decimal IP to a dotted IP
 sub dec2ip ($) {
 join '.', unpack 'C4', pack 'N', shift;
# this sub converts a dotted IP to a decimal IP
 sub ip2dec ($) {
 unpack N => pack CCCC => split /./ => shift;