防止ARP攻击的shell代码

发布时间:2019-10-25编辑:脚本学堂
防止ARP攻击的shell代码

防止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."