From owner-freebsd-questions Tue Jun 4 16:44:36 2002 Delivered-To: freebsd-questions@freebsd.org Received: from pooh.ASARian.org (pooh.ASARian.org [216.21.171.83]) by hub.freebsd.org (Postfix) with ESMTP id 8FD8437B400 for ; Tue, 4 Jun 2002 16:44:31 -0700 (PDT) Received: from localhost (fuzzy@localhost.ASARian.org [127.0.0.1]) by pooh.ASARian.org (8.11.6/8.11.6) with ESMTP id g54NigJ29253; Tue, 4 Jun 2002 19:44:42 -0400 (EDT) (envelope-from fuzzy@pooh.ASARian.org) Date: Tue, 4 Jun 2002 19:44:42 -0400 (EDT) From: Fuzzy To: BSD Freak Cc: FreeBSD Questions Subject: Re: Getting network and broadcast addresses in a shell script In-Reply-To: Message-ID: X-No-Archive: Yes Organization: ASARian Inc. MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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