denyhosts/denyhosts.sh

64 lines
1.3 KiB
Bash
Raw Normal View History

2019-09-24 08:53:00 +08:00
#!/bin/bash
#
# System authorization information.
# SSH prevents violent cracking
# Email: aixiao@aixiao.me
# Time: 20170909
#
2022-07-07 16:52:24 +08:00
source /etc/profile
2019-09-24 08:53:00 +08:00
function init() {
SEND_MAIL=1
2022-07-07 16:52:24 +08:00
PWD_PATH="/root";
2019-09-24 08:53:00 +08:00
TIME=`date +"%Y%m%d%H%M"`;
2022-07-07 16:52:24 +08:00
LOG_FILE="${PWD_PATH}/${TIME}.log";
EMAIL_ADDRESS="1605227279@qq.com";
IPTABLES=$(which iptables)
IPTABLES_SAVE=$(which iptables-save)
2019-09-24 08:53:00 +08:00
}
function run()
{
2022-07-07 16:52:24 +08:00
echo "Read-Only Memory,ROM:" &>> ${LOG_FILE}
df -am &>> ${LOG_FILE}
2019-09-24 08:53:00 +08:00
2022-07-07 16:52:24 +08:00
echo "random access memoryRAM:" &>> ${LOG_FILE}
free -hl &>> ${LOG_FILE}
2019-09-24 08:53:00 +08:00
2022-07-07 16:52:24 +08:00
echo "System process:" &>> ${LOG_FILE}
ps -auxwwf &>> ${LOG_FILE}
2019-09-24 08:53:00 +08:00
2022-07-07 16:52:24 +08:00
echo "Network Connections" &>> ${LOG_FILE}
netstat -tnulp &>> ${LOG_FILE}
2019-09-24 08:53:00 +08:00
2022-07-07 16:52:24 +08:00
echo "System SSH authorization information:" &>> ${LOG_FILE}
2022-10-13 18:01:06 +08:00
/root/denyhosts/rhost | grep -E "^[0-9]" | awk '{a[$1]+=1;} END {for(i in a){print a[i]" "i;}}' &>> ${LOG_FILE}
2021-07-11 10:10:55 +08:00
2022-07-07 16:52:24 +08:00
$IPTABLES_SAVE > /root/ipv4tables
2019-09-24 08:53:00 +08:00
2022-07-07 16:52:24 +08:00
echo "" &>> ${LOG_FILE}
echo "Iptables filter table" &>> ${LOG_FILE}
$IPTABLES -L -n --line-numbers &>> ${LOG_FILE}
echo "" &>> ${LOG_FILE}
2019-09-24 08:53:00 +08:00
2022-07-07 16:52:24 +08:00
if test $SEND_MAIL = 1; then
mail -s "System Log" ${EMAIL_ADDRESS} < ${LOG_FILE}
rm ${LOG_FILE}
2019-09-24 08:53:00 +08:00
fi
2022-06-26 19:49:00 +08:00
2019-09-24 08:53:00 +08:00
sync
}
init;
run;
exit 0;
20190103
20190911
2019-10-22 23:08:05 +08:00
20191008
2021-07-11 10:10:55 +08:00
20210614
2019-09-24 08:53:00 +08:00
aixiao@aixiao.me