Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jun 2002 19:44:42 -0400 (EDT)
From:      Fuzzy <fuzzy@pooh.ASARian.org>
To:        BSD Freak <bsd-freak@mbox.com.au>
Cc:        FreeBSD Questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Getting network and broadcast addresses in a shell script
Message-ID:  <Pine.BSF.4.44.0206041921180.26661-100000@pooh.ASARian.org>
In-Reply-To: <dd3f13dcfdec.dcfdecdd3f13@mbox.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help



On Tue, 4 Jun 2002, BSD Freak wrote:

> Hi all,
>
> I have the following shell script I am writing in which I need to get
> the $network and $broadcast:
>
> #!/bin
> netmask=255.255.255.0
> ip=192.168.0.1
>
> network=`do some magic with $netmask and $ip`
> broadcast=`do some more magic with $netmask and $ip`
>
> echo $network
> echo $broadcast
>

I extract them from cidr.

network=`/path/to/cidr -q $ip -q $netmask|tail +5|head -1|awk '{print $2}'`
broadcast=`/path/to/cidr -q $ip -q $netmask|tail +6|head -1|awk '{print $2}'`

/usr/ports/net/cidr

/usr/ports/net/cidr/pkg-descr:

cidr is a tiny command-line tool for determining network and broadcast
addresses a la RFC 1878.  It takes an IP address and netmask and
outputs the network address, broadcast address, and total number of
addresses for the corresponding subnet.  The IP can be in binary,
decimal, hex, or dotted quad.  The mask can be in binary, decimal, hex,
dotted quad, or prefix.

Fuzzy


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.44.0206041921180.26661-100000>