-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAC-ADDRESS-Renewal.sh
More file actions
executable file
·86 lines (65 loc) · 3.24 KB
/
Copy pathMAC-ADDRESS-Renewal.sh
File metadata and controls
executable file
·86 lines (65 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
export PATH="$PATH/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
export LANG=C
# define directory & files
WORKDIR=/usr/local/etc/nmap-tool
MTMPDIR=$WORKDIR/mtmp-dir
MACADDRLOGFILE=$MTMPDIR/macaddr-logfile
PROGRAMSTOPPEDREASON=$MTMPDIR/program_stopped_reason
CURLHTTPSTATUSCODE=$MTMPDIR/curl_http-status_code
DATETIME=$MTMPDIR/date-time
BACKUPDIR=$WORKDIR/backup
NMAP_DIR=nmap
# for MacPC
# NMAP_MAC_ADDR_DIR=/usr/local/share/nmap
# for Linux
NMAP_MAC_ADDR_DIR=/usr/share/nmap/
NMAP_MAC_PREFIXES=nmap-mac-prefixes
CURRENT_NMAC_MAC=$NMAP_MAC_ADDR_DIR/$NMAP_MAC_PREFIXES
#BACKUP_NMAC_MAC=$BACKUPDIR/nmap-mac-prefixes_`cat $DATETIME`
#if test -e $DATETIME ; then
# rm $DATETIME
# echo "remove $DATETIME file "
#fi
# Remove TMP file
if [ test -e $MTPMDIR/* ; then
cd $MTPMDIR
rm *
echo "tmp-file"
fi
echo `date "+%Y%m%d%H%M%S"` > $DATETIME
cd $WORKDIR
echo "------------------------"
echo "NEW-MAC-ADDRESS-LIST GET START : `date "+%Y%m%d%H%M%S"`" > $MACADDRLOGFILE
#curl -OL -f http://standards.ieee.org/regauth/oui/oui.txt
#curl http://standards-oui.ieee.org/oui/oui.txt -o /dev/null -w "%{http_code}\t\n" 2> /dev/null
#curl http://standards-oui.ieee.org/oui/oui.txt -o /dev/null -w "%{http_code}\t\n" 2> /dev/null > curl_start_time-and-status_code
echo "curl start time is" `date "+%Y%m%d%H%M%S"` >> $MACADDRLOGFILE
curl -OL -f http://standards-oui.ieee.org/oui/oui.txt -w "%{http_code}\t\n" 2> /dev/null > $CURLHTTPSTATUSCODE
#curl -OL -f http://standards.ieee.org/regauth/oui/oui.txt -w "%{http_code}\t\n" 2> /dev/null > $CURLHTTPSTATUSCODE
echo "NEW-MAC-ADDRESS-LIST GET Finish : `date "+%Y%m%d%H%M%S"`" >> $MACADDRLOGFILE
if test 200 != `cat $CURLHTTPSTATUSCODE` ; then
echo " " ;
echo " " ;
echo "This program has been stopped." > $PROGRAMSTOPPEDREASON
echo "curl http status code is `cat $CURLHTTPSTATUSCODE`" >> $PROGRAMSTOPPEDREASON
echo "stopped time is" `date "+%Y%m%d%H%M%S"` >> $PROGRAMSTOPPEDREASON
else
#curl -OL -f http://standards-oui.ieee.org/oui/oui.txt
cp oui.txt today_dir/oui.txt_`cat $DATETIME`
echo "------------------------" >> $MACADDRLOGFILE
echo "Backup the Current-MAC-ADDRESS-DATA: `date "+%Y%m%d%H%M%S"`" >> $MACADDRLOGFILE
cat auth.txt |sudo -S cp $CURRENT_NMAC_MAC $BACKUPDIR/nmap_mac_prefixes_`cat $DATETIME`
echo "Backup finish: `date "+%Y%m%d%H%M%S"`" >> $MACADDRLOGFILE
echo "------------------------" >>$MACADDRLOGFILE
echo "------------------------" >>$MACADDRLOGFILE
echo "Convert format OUI and update NMAP-MAC-Prefixes. : `date "+%Y%m%d%H%M%S"`" >> $MACADDRLOGFILE
cat auth.txt | sudo -S perl make-mac-prefixes.pl oui.txt $CURRENT_NMAC_MAC
echo "Convert finish : `date "+%Y%m%d%H%M%S"`" >> $MACADDRLOGFILE
echo "------------------------" >>$MACADDRLOGFILE
echo "Check the difference for before and after: : `date "+%Y%m%d%H%M%S"`" >> $MACADDRLOGFILE
diff $CURRENT_NMAC_MAC $BACKUPDIR/nmap_mac_prefixes_`cat $DATETIME` >$BACKUPDIR/`cat $DATETIME`_diff
echo "Check finish : `date "+%Y%m%d%H%M%S"`" >> $MACADDRLOGFILE
echo "------------------------" >> $MACADDRLOGFILE
echo "finish the this process: : `date "+%Y%m%d%H%M%S"`" >> $MACADDRLOGFILE
fi