Skip to content

Instantly share code, notes, and snippets.

@adkinss
Created August 12, 2016 14:32
Show Gist options
  • Save adkinss/d071bc4805b9dc0f28cd450c5e3b9c4d to your computer and use it in GitHub Desktop.
Save adkinss/d071bc4805b9dc0f28cd450c5e3b9c4d to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
# Converts an integer number representing an IP back into an IP address string
use strict;
sub ip_to_int ($)
{
my $addr = shift @_;
return unpack("N", pack("C4", split(/\./, $addr)));
}
sub int_to_ip ($)
{
my $addr = shift @_;
return join(".", unpack("C4", pack("N", $addr)));
}
foreach (@ARGV) {
print "$_ = ", ip_to_int($_), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment