#!/usr/bin/perl -w use strict; use Socket; for my $host (@ARGV) { my $addr = inet_ntoa( scalar gethostbyname($host) ); my $bin; $bin .= dec2bin($_) for (split /[.]/, $addr); print bin2dec($bin), "\n"; } sub bin2dec { unpack("N", pack("B32", substr("0" x 32 . shift, -32))); } sub dec2bin { my $str = unpack("B32", pack("N", shift)); # we only need the lowest 8 bits (ipv4 range 0-255) return substr $str, length($str) - 8; }
Now load up your browser and be amazed! (your perlmonks cookie will, of course, not work)[ar0n@zendo perl]% perl ip2dec.pl perlmonks.org 3467251275
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Convert hostname to decimal form
by japhy (Canon) on Oct 22, 2000 at 05:01 UTC | |
|
Re: Convert hostname to decimal form
by Anonymous Monk on Nov 24, 2000 at 18:36 UTC | |
|
Re: Convert hostname to decimal form
by bittondb (Novice) on Oct 08, 2001 at 06:57 UTC |