Skip to content

Instantly share code, notes, and snippets.

@benmeyer50
Created March 3, 2014 19:48
Show Gist options
  • Save benmeyer50/9333144 to your computer and use it in GitHub Desktop.
Save benmeyer50/9333144 to your computer and use it in GitHub Desktop.
Convert 10 digit int into IP Address
#!/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