デフォルトゲートウェイのMACアドレスを監視するためのスクリプトを作成し、ARP攻撃が見つかった場合にアラートを出します。しかし、実行中にエラーが発生しました。
正規表現で結果を返すことはできません。これはLinuxスクリプト用です
#!/bin/bash
function getmac {
dg = netstat -rn | grep -Eo 'default.*([0-9]{1,3}\.){3}[0-9]{1,3}' #grab the default gateway (DG)
dg_ip= $dg | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' #strip the DG to just IP
dg_arp = arp -a | grep -w $dg_ip #grab the arp entry for DG
dg_mac=$(echo $dg_arp | grep -Eo '[0-9a-f]{1,2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}') #strip the ARP entry to just the MAC
echo "netstat shows "$dg
echo "DG IP shows "$dg_ip
echo "arp shows "$dg_arp
echo "DG MAC shows "$dg_mac
}
よろしくお願いします。私の英語から申し訳ありません。