Skip to content

Instantly share code, notes, and snippets.

@adkinss
Created August 12, 2016 14:34
Show Gist options
  • Select an option

  • Save adkinss/10c9688e3bac1a23ef42a0d18888377e to your computer and use it in GitHub Desktop.

Select an option

Save adkinss/10c9688e3bac1a23ef42a0d18888377e to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
# Converts an IP address string to a single integer number
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 "$_ = ", int_to_ip($_), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment