Updated,
given,
INPUT="192.168.10.0/24"
NETWORK=`ipcalc -s -n "$INPUT" | awk -F= '{ print $2; }'`
BROADCAST=`ipcalc -s -b "$INPUT" | awk -F= '{ print $2; }'`
ADDR=""
NET=`echo "$NETWORK" | awk -F. '{ print $1; }'`
BST=`echo "$BROADCAST" | awk -F. '{ print $1; }'`
if [ "$NET" = "$BST" ]; then
ADDR="${ADDR}${NET}."
NET=`echo "$NETWORK" | awk -F. '{ print $2; }'`
BST=`echo "$BROADCAST" | awk -F. '{ print $2; }'`
if [ "$NET" = "$BST" ]; then
ADDR="${ADDR}${NET}."
NET=`echo "$NETWORK" | awk -F. '{ print $3; }'`
BST=`echo "$BROADCAST" | awk -F. '{ print $3; }'`
if [ "$NET" = "$BST" ]; then
ADDR="${ADDR}${NET}."
fi
fi
fi
MASK=`ipcalc -s -m "$INPUT" | awk -F= '{ print $2; }'`
then, the matching interface will be spit out with the following:
----
ifconfig -a | \
sed -e :a -e N -e 's/\n / /' -e ta | \
grep -i "inet addr:$ADDR" | \
grep -i "mask:$MASK" | \
awk '{ print $1; }'
----
sed description, Join lines that begin begin with 10 spaces
----
:a # label 'a' to jump back to later on
N # Append next line to sed's buffer
s/\n / / # replace exactly one newline (\n) followed by 10
spaces with one space
ta # if the last replace command was succesfull, jump to label 'a'.
----
Hope this works for you.
Lonnie
On Sep 27, 2008, at 1:54 AM, Philip Prindeville wrote:
> Hmmm.... found a minor but really annoying bug in the IPSec code.
> The
> fix is simple, but difficult to automate in bash.
>
> Anyone have an easy to figure out which interface corresponds to a
> particular network?
>
> For instance, if I have the below, then for input "192.168.10.0/24",
> then I want the output to be "br1".
>
> Anyone know of an easy way to do this? I could do it with perl easily
> enough, but that's not an option here...
>
> Thanks,
>
> -Philip
>
>
> pbx asturw # ifconfig -a
> br1 Link encap:Ethernet HWaddr 00:00:24:C9:30:01
> inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:
> 255.255.255.0
> UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
> RX packets:3003724 errors:0 dropped:0 overruns:0 frame:0
> TX packets:3559171 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:0
> RX bytes:657264449 (626.8 MiB) TX bytes:2817445211 (2.6 GiB)
>
> eth0 Link encap:Ethernet HWaddr 00:00:24:C9:30:00
> BROADCAST MULTICAST MTU:1500 Metric:1
> RX packets:0 errors:0 dropped:0 overruns:0 frame:0
> TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:1000
> RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
> Interrupt:11 Base address:0xe100
>
> eth1 Link encap:Ethernet HWaddr 00:00:24:C9:30:01
> UP BROADCAST MULTICAST MTU:1500 Metric:1
> RX packets:0 errors:0 dropped:0 overruns:0 frame:0
> TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:1000
> RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
> Interrupt:5 Base address:0xe200
>
> eth2 Link encap:Ethernet HWaddr 00:00:24:C9:30:02
> UP BROADCAST MULTICAST MTU:1500 Metric:1
> RX packets:0 errors:0 dropped:0 overruns:0 frame:0
> TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:1000
> RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
> Interrupt:9 Base address:0xe300
>
> eth3 Link encap:Ethernet HWaddr 00:00:24:C9:30:03
> UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
> RX packets:3004590 errors:0 dropped:0 overruns:0 frame:0
> TX packets:3559171 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:1000
> RX bytes:705856587 (673.1 MiB) TX bytes:2817445211 (2.6 GiB)
> Interrupt:12 Base address:0xe400
>
> lo Link encap:Local Loopback
> inet addr:127.0.0.1 Mask:255.0.0.0
> UP LOOPBACK RUNNING MTU:16436 Metric:1
> RX packets:0 errors:0 dropped:0 overruns:0 frame:0
> TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:0
> RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
>
> ppp0 Link encap:Point-to-Point Protocol
> inet addr:63.224.43.230 P-t-P:63.231.10.208 Mask:
> 255.255.255.255
> UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
> RX packets:2844038 errors:0 dropped:0 overruns:0 frame:0
> TX packets:2456032 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:3
> RX bytes:2633750422 (2.4 GiB) TX bytes:587350974 (560.1 MiB)
>
> w1ad Link encap:Ethernet HWaddr 00:77:77:77:82:7B
> UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
> RX packets:3014870 errors:0 dropped:0 overruns:0 frame:0
> TX packets:2667819 errors:0 dropped:0 overruns:0 carrier:0
> collisions:0 txqueuelen:1000
> RX bytes:2778831161 (2.5 GiB) TX bytes:673146887 (641.9 MiB)
> Interrupt:10 Memory:d0880000-d0881fff
>
> pbx asturw # route -n
> Kernel IP routing table
> Destination Gateway Genmask Flags Metric Ref
> Use Iface
> 63.231.10.208 0.0.0.0 255.255.255.255 UH 0
> 0 0 ppp0
> 192.168.10.0 0.0.0.0 255.255.255.0 U 0
> 0 0 br1
> 224.0.0.0 0.0.0.0 240.0.0.0 U 0
> 0 0 br1
> 0.0.0.0 0.0.0.0 0.0.0.0 U 0
> 0 0 ppp0
>
>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win
> great prizes
> Grand prize is a trip for two to an Open Source event anywhere in
> the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Astlinux-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/astlinux-users
>
> Donations to support AstLinux are graciously accepted via PayPal to [EMAIL
> PROTECTED]
> .
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Astlinux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/astlinux-users
Donations to support AstLinux are graciously accepted via PayPal to [EMAIL
PROTECTED]