Plankton has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks!
I need to be able to convert integer versions of IPv4 address to the four octet version of the IP address. I have this script that works well but I need to embed this into a scriptlet in an RPM, so I was hoping someone could help stream-line it some.
#!/usr/local/bin/perl -w use strict; my $int = shift || 2130706433; # 127.0.0.1 my $quad4 = $int % 256; $int = int($int/256); my $quad3 = $int % 256; $int = int($int/256); my $quad2 = $int % 256; $int = int($int/256); my $quad1 = $int % 256; print "$quad1.$quad2.$quad3.$quad4\n";
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Integer IP address to Quad IPv4 address one liner or close to it?
by Fletch (Bishop) on Aug 06, 2009 at 17:43 UTC | |
|
Re: Integer IP address to Quad IPv4 address one liner or close to it?
by BrowserUk (Patriarch) on Aug 06, 2009 at 17:40 UTC | |
by Plankton (Vicar) on Aug 06, 2009 at 18:04 UTC | |
by BrowserUk (Patriarch) on Aug 06, 2009 at 18:43 UTC |