Created
March 3, 2014 19:48
-
-
Save benmeyer50/9333144 to your computer and use it in GitHub Desktop.
Convert 10 digit int into IP Address
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 10 digit int into IP Address | |
use strict; | |
use warnings; | |
sub usage | |
{ | |
print "Usage: inttoip.pl intaddr\n"; | |
exit 1; | |
} | |
if(@ARGV != 1) | |
{ | |
&usage; | |
} | |
my $inttoconvert = $ARGV[0]; | |
my @convertoctets; | |
$convertoctets[3] = $inttoconvert % 256; | |
$inttoconvert = int($inttoconvert/256); | |
$convertoctets[2] = $inttoconvert % 256; | |
$inttoconvert = int($inttoconvert/256); | |
$convertoctets[1] = $inttoconvert % 256; | |
$inttoconvert = int($inttoconvert/256); | |
$convertoctets[0] = $inttoconvert % 256; | |
my $convertedint = join(".", @convertoctets); | |
print "$convertedint\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment