从日志中检查MAC

时间:2015-08-22 13:32:37

标签: linux macos bash mac-address

我目前有一个检查MAC地址的脚本,tt看起来像这样

  "m"|"-m" )
    if [ ! -n "$2" ]
    then
        echo "Enter MAC address"
        exit 0
    fi

     out1=`cat $dhcp_files/* | grep -i "$2" 2>/dev/null`
     ip=`cat $dhcp_files/* | grep -i "$2" | awk '{print $8}' | sed s/\;//g  2>/dev/null`
     out=` grep -i $ip $shapy/*  | awk '{print $8}'  2>/dev/null`
     echo -en ''$out1'  on  '$out'  \n'

这样做:./mac_check -m 00:00:00:00:00:00

此脚本的结果:

host Jon_Rosewelt_6_5 { hardware ethernet 00:1d:4e:b5:d4:10; fixed-address 192.168.101.19; }  on  eth4  

但我想对脚本收到任何形式的mac地址

又名。 ./check_mac -m 001d.4eb5.d410 **or** 001d4eb5d410 **or** 00-1d-4e-b5-d4-10

我该怎么做?

1 个答案:

答案 0 :(得分:1)

使用GNU sed和Solaris sed:

<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

输出:

00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10

使用您的代码:

echo 001d.4eb5.d410 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 001d4eb5d410 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 00-1d-4e-b5-d4-10 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 00:1d:4e:b5:d4:10 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'