Created
August 12, 2016 14:34
-
-
Save adkinss/10c9688e3bac1a23ef42a0d18888377e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -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