nv-l
[Top] [All Lists]

Re: Determining Network Address

To: nv-l@lists.tivoli.com
Subject: Re: Determining Network Address
From: "Les Dickert" <lesdickert@hotmail.com>
Date: Fri, 20 Apr 2001 19:31:23
Below is an awk program that can determine
the network part of a dotted decimal formatted
IP address and subnet mask.  Of course if
you're running NetView on NT it may not help
unless you get awk for NT.

Seems to work, but let me know if it doesn't.

Feel free to copy it and use it as you wish.
Remember you get what you pay for!

Thanks,

Les Dickert
Verisign Consulting
04-20-2001

### ipnet.ap ##################################
#
#  This awk program takes an IP address
#  and subnet mask and determines the network
#  number and prints it in dotted decimal
#  format.
#
#  Usage examples:
#
#   awk -f ipnet.ap -v ADDR=172.20.184.69 -v MASK=255.255.255.0
#   172.20.184.0        <==== this is the output
#
#   awk -f ipnet.ap -v ADDR=172.20.184.69 -v MASK=255.255.224.0
#   172.20.160.0
#
#   awk -f ipnet.ap -v IP=172.20.184.69 -v SM=255.255.0.0
#   172.20.0.0
#
#   awk -f ipnet.ap -v IP=172.20.184.69 -v SM=255.0.0.0
#   172.0.0.0
#
#  Les Dickert
#  Verisign Consulting
#  04-20-2001
#
###############################################

BEGIN {

#  Break the IP address and subnet mask into
#  parts.

          FS = ".";
          split(IP, ip);
          split(SM, sm);

#  The following is yukky  because awk
#  does not have a logical AND operator
#  (tsk, tsk)

          for ( i=1; i<=4; i++ ) {
             if ( sm[i] == 255 ) np[i] = ip[i];
             else if ( sm[i] == 0   ) np[i] = 0;
                  else {  s = 256 - sm[i];
                          h = ip[i] % s;
                          np[i] = ip[i] - h;
                  }
          }
          printf("%d.%d.%d.%d\n", np[1], np[2], np[3], np[4]);

}
#### end of awk program ################################

>From: "Leslie Clark" <lclark@US.IBM.COM>
>Reply-To: IBM NetView Discussion <nv-l@tkg.com>
>To: IBM NetView Discussion <nv-l@tkg.com>
>Subject: Re: [NV-L] Determining Network Address
>Date: Thu, 19 Apr 2001 17:31:43 -0400
>
>Don, did you ever find something (or write something) to do this? Want to
>share? It seems to me that it would be handy for use in T/EC rules, since
>the
>Network Unreachable event includes the network address and the mask.
>
>Cordially,
>
>Leslie A. Clark
>IBM Global Services - Systems Mgmt & Networking
>Detroit
>
>
>DON-N-DARLA@att.net@tkg.com on 10/09/2000 07:49:03 PM
>
>Please respond to IBM NetView Discussion <nv-l@tkg.com>
>
>Sent by:  owner-nv-l@tkg.com
>
>
>To:   nv-l@tkg.com
>cc:
>Subject:  [NV-L] Determining Network Address
>
>
>
>Does anyone have a simple utility that, given an
>IP Address and the subnet-mask, determine the
>Network Address? I need to be able to do this from a
>script, using the information in the TopM Interface List
>NetView field.
>
>Don Davis
>_________________________________________________________________________
>NV-L List information and Archives: http://www.tkg.com/nv-l
>
>
>_________________________________________________________________________
>NV-L List information and Archives: http://www.tkg.com/nv-l

_________________________________________________________________


<Prev in Thread] Current Thread [Next in Thread>

Archive operated by Skills 1st Ltd

See also: The NetView Web