On 7/21/07, Archimerged Ark Submedes <[EMAIL PROTECTED]> wrote:
On 7/20/07, Mike Frysinger <[EMAIL PROTECTED]> did not read the question.
Neither did you. ;-) Asked for was a solution using ifconfig and bash; you added grep and tr. Yes, that's entirely reasonable on your part, but it's not necessary.
The answer is: /sbin/ifconfig eth0 | grep 'inet addr' | tr .: ' ' | (read inet addr a b c d Bcast e f g h Mask i j k l; echo $(($a & $i)).$(($b & $j )).$(( $c & $k )).$(( $d & $l )) )
Here's an ugly way to do it: NETADDR=`/sbin/ifconfig | while read w d z z; do if [ "$w" = "inet" ]; then d=${d#addr:}; z=${z#Mask:}; a=${d%%.*}; w=${z%%.*}; d=${d#*.}; z=${z#*.}; b=${d%%.*}; x=${z%%.*}; d=${d#*.}; z=${z#*.}; c=${d%%.*}; y=${z%%.*}; d=${d#*.}; z=${z#*.}; echo $((a&w)).$((b&x)).$((c&y)).$((d&z)); break; fi; done` And here's a better way, inspired by your use of 'tr': NETADDR=`/sbin/ifconfig | while read w x y y; do if [ "$w" = "inet" ]; then set -- ${x//./ }; a=${1#addr:}; b=$2; c=$3; d=$4; set -- ${y//./ }; w=${1#Mask:}; x=$2; y=$3; z=$4; echo $((a&w)).$((b&x)).$((c&y)).$((d&z)); break; fi; done` Dave _______________________________________________ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash