Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Converting hex IP addresses to decimal

by Coyote (Deacon)
on Jan 27, 2001 at 04:59 UTC ( #54688=snippet: print w/ replies, xml ) Need Help??

Description: Small function to convert hex IP address to decimal. For example, ff.ff.ff.0 becomes 255.255.255.0
sub hex2ip{
    return join(".", map {hex($_)} split(/\./,shift));
}
Comment on Converting hex IP addresses to decimal
Download Code
Replies are listed 'Best First'.
Re: Converting hex IP addresses to hex
by AltBlue (Chaplain) on Jan 27, 2001 at 05:27 UTC
    and again a regexp version: s/(\w+)/hex($1)/eg :)

    --
    AltBlue.

Re: Converting hex IP addresses to decimal
by Clownburner (Monk) on Oct 30, 2001 at 03:55 UTC
    And for those unfortunate souls who get their IP addresses in unsigned, non-delimited hex (ala SNMP agents):
    sub hex2ip { return join(".", map {hex($_)} unpack('A2 A2 A2 A2',shift +)) }

    "Non sequitur. Your facts are un-coordinated." - Nomad

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://54688]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2015-07-08 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls