Created
July 15, 2014 03:00
-
-
Save hmmbug/e386274e299ab4d00a9f to your computer and use it in GitHub Desktop.
bash - calculate network address from IP address & netmask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
IP_ADDR=$(hostname -i) | |
IFS=. read -r io1 io2 io3 io4 <<< "$IP_ADDR" | |
IFS=. read -r mo1 mo2 mo3 mo4 < <(ifconfig -a | sed -n "/inet addr:$IP_ADDR /{ s/.*Mask://;p; }") | |
NET_ADDR="$((io1 & mo1)).$(($io2 & mo2)).$((io3 & mo3)).$((io4 & mo4))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment