防止ARP攻击,使用命令route、grep、ifconfig等。
#!/bin/bash
declare gw=`route -n | grep -e '^0.0.0.0'`
declare gwname=`echo $gw | grep -oe 'w*$'`
declare gwip=`echo $gw | grep -oe '[0-9]{2,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}'`
declare gwmac=`arp -n | grep -e $gwip | grep -oe '[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-
F]{2}:[0-9A-F]{2}:[0-9A-F]{2}'`
echo "switch $gwname arp: $gwip - $gwmac to static"
arp -s $gwip $gwmac
echo "done, off arp reuqest .."
ifconfig $gwname -arp
echo "all done."