Re: Convert CDIR notation to IP range

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am Mi, den 28.07.2004 schrieb John Nichel um 18:21:

>    My binary skills are lacking, so does anyone know of a tool (online 
> or otherwise) to convert CDIR notation into the physical IP range?  eg 
> convert 192.168.0.0/24 into 192.168.0.0 through 192.168.0.255 (so I can 
> see what the actual range is).  TIA

> John C. Nichel

#!/usr/bin/perl -w
# $Id: cidr,v 0.1 2002/08/26 15:18:45 gm Exp $
# convert CIDR notation to network/broadcast/netmask notation
$Usage =  "usage: $0 [-s] ipaddr/bits\n\tipaddr in dotted squad\n";
$ARGV[0] or die $Usage; shift && $set++ if $ARGV[0] eq '-s';
$ARGV[0] or die $Usage; ($hostaddr,$bits) = split(/\//,$ARGV[0]);
(($hostaddr =~ /^(\d{1,3}\.){3}\d{1,3}$/) && $bits =~ /^\d{1,2}$/ ) ||
die $Usage;
print "$ARGV[0]: " unless $set;
$addr = pack("C4",split(/\./,$hostaddr));
$net = $addr & ($mask = pack("N",-(1<<(32-($bits % 32)))));
$brc = $addr | ~ $mask;
for($net,$brc,$mask){ $_ = join('.', unpack("C4",$_)) }
print $set ? "$hostaddr" : "network $net", " broadcast $brc netmask
$mask\n";

[ hope it survives line wrapping ]

Alexander


-- 
Alexander Dalloz | Enger, Germany | GPG key 1024D/ED695653 1999-07-13
Fedora GNU/Linux Core 2 (Tettnang) kernel 2.6.6-1.435.2.3.ad.umlsmp 
Serendipity 19:00:43 up 2 days, 4:07, load average: 1.23, 1.12, 1.08 

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux