Re: Bash scripting help...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/7/06, Jacques B. <jjrboucher@xxxxxxxxx> wrote:
Or even easier:

ip=$(/sbin/arping -f -I eth0 10.255.255.1 | grep Unicast | awk '{print
substr($5,2,17)}')

This greps for the line with the MAC, then using awk prints out the
5th field (space delimited by default so this is the MAC with the [
and ]), and using substr I carve out the MAC by saying I want the 5th
field ($5), starting at the 2nd character, for 17 characters.

Jacques B.

Of course both examples require you to put in the IP you wish to
target.  Remember that if the IP is on another subnet that the MAC
that you will get will be the last physical hop to you, so the
router/switch/ at the mouth of your subnet.  Check your gateway's MAC.
If you get that as a reply, then you know it's something outside of
your network (if you aren't sure to start off with).  You could always
write a condition in your script where you'd get the MAC of your
gateway and return a warning to the end user if they query an IP other
than the gateway that returns the gateway's MAC.

Jacques B.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux