본문 바로가기

Learning/└◆Shell Scripts

MAC 충돌 점검 프로그램 작성

# vi mac+check.sh

ping 172.16.6.200 ~ 172.16.6.230
arp -an > arp.txt
 172.16.6.200 mac1
 172.16.6.201 mac2
 172.16.6.202 mac3
 ...
 172.16.6.230 mac30
같은 MAC주소를 갖는 IP를 확인하고 싶다.
-------------------------------------
맥 어드레스 충돌. IP는 같은데 맥어드레스가 충돌나는 경우
--------------------------------------
./mac_check.sh 수행결과

172.16.6.200  mac1
172.16.6.201 mac1
172.16.6.220 mac20
172.16.6221 mac20
--------------------------------------
ex)중복 출력 solt cmd 비교 diff cmd

파일의 내용을 만들고  내용의 중첩을 점검해서 확인할수 있는 프로그램 작성.
맥 어드레스 변경 요청 문구 출력.

 


# vi macarp.txt
? (172.16.6.200) at 00:0C:29:26:B3:90 [ether] on eth0
? (172.16.6.201) at 00:0C:29:26:B3:91 [ether] on eth0
? (172.16.6.202) at 00:0C:29:26:B3:92 [ether] on eth0
? (172.16.6.203) at 00:0C:29:22:92:D7 [ether] PERM on eth0
? (172.16.6.204) at 00:0C:29:22:92:D8 [ether] PERM on eth0
? (172.16.6.205) at 00:0C:29:22:92:D9 [ether] PERM on eth0
? (172.16.6.206) at 00:0C:29:22:92:D7 [ether] PERM on eth0
? (172.16.6.207) at 00:0C:29:26:B3:90 [ether] on eth0


# cat macarp.txt | awk '{print $4}'
# cat macarp.txt|awk '{print $4}'|grep -v incomplete|uniq -d|sort | uniq -d
00:0C:29:26:B3:90

# grep 00:0C:29:26:B3:90 macarp.txt | awk '{print $2 $4}'


-------------------------------------------------------------------------
#!/bin/bash

START=200
END=230
NET=172.16.6

> result.txt

#while [ $START -le $END ]
#do
#   ping -c 1 $NET.$START >/dev/null 2>&1
#       if [ $? -eq 0 ] ; then
#           echo -n "$NET.$START : [alive]" ;echo
#       else
#           echo -n "$NET.$START : [DEAD]" ;echo
#       fi
#done
#
#arp -an > macarp.txt

cat macarp.txt | awk '{print $4}' | \
        sort | \
        uniq -d | \
        grep -v incomplete > macarp2.txt


cat macarp2.txt | while read MAC
do
    grep $MAC macarp.txt | awk '{print $2, $4}' >> result.txt
done

echo "---`date`---"
echo "--- arp2.txt---";echo
cat macarp2.txt
echo
echo "--- result.txt---"
cat result.txt
-------------------------------------------------------