Created
March 3, 2014 19:37
-
-
Save benmeyer50/9332966 to your computer and use it in GitHub Desktop.
Convert IPv4 Address to 10 digit integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
#Author: Benjamin Meyer | |
#Date: 3/3/14 | |
#Purpose: Convert IP to 10 digit integer; | |
use strict; | |
use warnings; | |
sub usage | |
{ | |
print "Usage: iptoint.pl ipaddress\n"; | |
exit 1; | |
} | |
if(@ARGV != 1) | |
{ | |
&usage; | |
} | |
my $iptoconvert = $ARGV[0]; | |
my @octets = split(/\./, $iptoconvert); | |
my @convertoctets; | |
$convertoctets[0] = $octets[0]*16777216; | |
$convertoctets[1] = $octets[1]*65536; | |
$convertoctets[2] = $octets[2]*256; | |
$convertoctets[3] = $octets[3]; | |
my $convertedip = 0; | |
foreach(@convertoctets) | |
{ | |
$convertedip += $_; | |
} | |
print $convertedip."\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment