Re: netmask in a script

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Brian Cluff
Date:  
To: Main PLUG discussion list
Subject: Re: netmask in a script
Is this along the lines of what you are looking for?
You'll need to install ipcalc first

#!/bin/bash
TEMP=$(ifconfig eth0 |grep 'inet addr')
ADDRESS=$(echo $TEMP|cut -f2 -d:)
ADDRESS=${ADDRESS% *}
MASK=$(echo $TEMP|cut -f4 -d:)
NETTEMP=$(ipcalc $ADDRESS/$MASK|grep Network)
NETTEMP=${NETTEMP#*: }
NETWORK=${NETTEMP%/*}
echo $NETWORK

Brian Cluff

On 10/26/2011 09:49 PM, Dazed_75 wrote:
> I would like to apply a netmask to an arbitrary IP in a bash/dash script
> (e.g. apply 255.255.255.0 to 173.10.3.155 to get 173.10.3.0).Is there
> any easy way to do that without taking the IP apart, doing 4 operations
> and reassembling the results?
>
> --
> Dazed_75 a.k.a. Larry
>
> The spirit of resistance to government is so valuable on certain
> occasions, that I wish it always to be kept alive.
>- Thomas Jefferson
>
>
> ---------------------------------------------------
> PLUG-discuss mailing list -
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss