Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
There's more than one way to do things
 
PerlMonks

IP2HEX

by spp (Initiate)
on May 16, 2000 at 19:44 UTC ( #11876=snippet: print w/ replies, xml ) Need Help??

Description: Convert an IP address to its hex value. Useful when setting up network boot under Sun. For example: ip2hex 192.168.21.1 returns IP 192.168.21.1 is HEX C0A81501
#!/usr/local/bin/perl

# IP address to HEX address converter
# usage: ip2hex [ip]
# ip2hex 158.23.45.10
# outputs 9E172D0A
# version 1.0

use Getopt::Std;

($me = $0) =~ s|.*/||;

getopts("h");

die "Usage: $me [ip]\n" if $opt_h;

$ip = $ARGV[0];

if (! $ip) {
        print "Enter IP addr: ";
        chop($ip = <STDIN>);
}

print "IP $ip is HEX ";
foreach (split /\./, $ip) {
        printf "\U%02x", $_;
}
print "\n"; 
Comment on IP2HEX
Download Code

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (19)
As of 2012-02-15 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When I see "10", I think:











    Results (538 votes), past polls