-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendlessh.sh
executable file
·51 lines (38 loc) · 942 Bytes
/
endlessh.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
#!/bin/sh
# Get connected endlessh hosts & send a mail
# Email options
# Change these!!
SUBJECT="Endlessh Report"
SENDER="endlessh@example.com"
RECIPIENT="postmaster@example.com"
# Create hosts list
hosts=$(grep "ACCEPT host" /var/log/syslog | awk "{print \$7}" | sed "s/host=::ffff://g" | sort -u)
# Temporarily copy hosts list to /tmp
echo "${hosts}" > /tmp/endlessh-report-tmp
# Get hosts info
# Change this!
hosts_info=$(/path/to/bad-cidrs/host_rec.sh /tmp/endlessh-report-tmp)
# Remove tmp file
rm /tmp/endlessh-report-tmp
# Get number of hosts
host_count=$(echo "${hosts}" | wc -l)
# Create mail message
message=$(cat <<EOF
Subject: ${SUBJECT}
To: ${RECIPIENT}
From: ${SENDER}
Hi,
this is the endlessh report.
Today ${host_count} host(s) tried to connect.
Hosts
================
${hosts}
Hosts WHOIS info
================
${hosts_info}
***
Generated at $(date).
EOF
)
# Send mail message
echo -e "${message}" | sendmail -t