forked from wedaa/LongTail-Log-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LongTail_nmap_hosts.sh
75 lines (61 loc) · 1.84 KB
/
LongTail_nmap_hosts.sh
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
#!/bin/sh
# This runs every hour through cron
########################################################################
#
# Get Today's IPs
#
echo -n "Starting at: "
date;
if [ -e "/var/tmp/LongTail_nmap_hosts.pid" ] ; then
echo "LongTail_nmap_hosts is still running, aborting out now"
else
echo "$$" > /var/tmp/LongTail_nmap_hosts.pid
fi
touch current-ip-addresses.txt
rm current-ip-addresses.txt
wget http://longtail.it.marist.edu/honey/current-ip-addresses.txt
grep -v \# current-ip-addresses.txt > current-ip-addresses-munged.txt
rm current-ip-addresses.txt
cd /var/www/html/nmap
DATE=`date +%Y-%m-%d`
for ip in `awk '{print $2}' current-ip-addresses-munged.txt ` ; do
if [ ! -e $ip.$DATE.txt ] ; then
echo "Scanning $ip now"
timeout 600 nmap --host-timeout 15m -v -A -Pn $ip > $ip.$DATE.txt
else
echo "Already have $ip"
fi
done
rm /var/tmp/LongTail_nmap_hosts.pid
echo -n "Done with TODAY at: "
date
########################################################################
#
# Double check we got all of yesterday's IPs
#
echo "Getting yesterday's IPs"
HOUR=`date +%H`
#if [ $HOUR -eq 1 ] ; then
YESTERDAY=`date +%Y-%m-%d --date="1 day ago"`
YESTERDAY_DIR=`date +%Y/%m/%d --date="1 day ago"`
touch todays_ips # Just to make sure it exists before I remove it
rm todays_ips
wget http://longtail.it.marist.edu/honey/historical/$YESTERDAY_DIR/todays_ips
grep -v \# todays_ips > todays_ips-munged.txt
touch todays_ips # Just to make sure it exists before I remove it
rm todays_ips
ls -l todays_ips-munged.txt
#cat todays_ips-munged.txt
for ip in `awk '{print $1}' todays_ips-munged.txt ` ; do
echo "ip is $ip"
if [ ! -e $ip.$YESTERDAY.txt ] ; then
echo "Scanning $ip now"
nmap -v -A -Pn $ip > $ip.$YESTERDAY.txt 2>&1
else
echo "$ip.$YESTERDAY.txt exists"
ls -l $ip.$YESTERDAY.txt
fi
done
#fi
echo -n "Done YESTERDAY at: "
date