[Dshield] IP representation

Ray Seals rseals at vdsi.net
Fri Aug 1 17:27:22 GMT 2003


Convert IP to decimal:

#!/usr/bin/perl

$_ = <STDIN>;

chomp($_);

$converteddecimal = ip2dec($_);
$convertedip = dec2ip($converteddecimal);

print "Beginning ip address: $_\n";
print "Decimal: $converteddecimal\n";
print "IP: $convertedip\n";

sub dec2ip ($) {
join '.', unpack 'C4', pack 'N', shift;
}

sub ip2dec ($) {
unpack N => pack CCCC => split /\./ => shift;
}


Convert interger to ip:

#!/usr/bin/perl

print "Please Enter Decimal IP number to convert: ";
$_ = <STDIN>;

chomp($_);

$converted = dec2ip($_);

print "IP Address: $converted\n";

sub dec2ip ($) {
join '.' => map { ($_[0] >> 8*(3-$_)) % 256 } 0 .. 3;
}


Ray


On Fri, 2003-08-01 at 10:52, Leone, Michael wrote:
> A while back (talking about early 90's old school) I came across
> representing ip addresses as a single long integer not in its period
> delimited form. Anybody remember the name of that, or even how it was
> converted? I wrote a sh script to convert the ip addresses back and forth
> but that's probably on an old scsi drive somewhere in a dust latent bsd
> server that has been sitting in my basement since desert storm. Today, I
> can't remember what it was called nor do I recall how to do it. Brain
> doesn't work so good these days, caffeine has short-circuited my memory.
> 
> ------------------------------------------------------------------------------
> Notice:  This e-mail message, together with any attachments, contains
> information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA), and/or
> its affiliates (which may be known outside the United States as Merck Frosst,
> Merck Sharp & Dohme or MSD) that may be confidential, proprietary copyrighted
> and/or legally privileged, and is intended solely for the use of the
> individual or entity named on this message.  If you are not the intended
> recipient, and have received this message in error, please immediately return
> this by e-mail and then delete it.
> ------------------------------------------------------------------------------
> 
> _______________________________________________
> list mailing list
> list at dshield.org
> To change your subscription options (or unsubscribe), see: http://www.dshield.org/mailman/listinfo/list
-- 
Ray Seals <rseals at vdsi.net>




More information about the list mailing list