shell腳本應用實戰

shell腳本應用實戰


 這個腳本主要記錄局域網中各主機的MAC地址
(每行的第一條記錄,第一列爲IP地址,第二行爲對應的MAC地址)

    通過arping命令發送arp請求,根據反饋結果記錄MAC地址

例如192.168.10網段    (arping-c2-w1192.168.10.1)
查看相應的IP地址對應的MAC地址
arp-n|grep-v'Address'|awk'{print$1,$3}'
    將文件保存到/etc/ether文件中
   
vimgetarp.sh

#!/bin/bash

foriin$(seq120);do
echo192.168.6.$i
arping-c1-w1192.168.6.$i&>/dev/null
done

if[-f/etc/ether];then
mv/etc/ether/etc/ether.bak
fi

:wq

arp-n|grep-v'Address'|awk'{print$1,$3}'>/etc/ether

bashgetarp.sh(執行一下腳本)
cat/etc/ether(查看結果)


掃描主機是否開啓22端口

vimscanhost.sh

#!/bin/bash


foriin$(awk'{print$1}'/etc/ether);do
#echowgetftp://$i

nc-z$i22

if[$?-eq0];then
echoHost$isshisup
else
echoHost$isshisdown
fi

done

bashscanhost.sh執行

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章