A script for ssh
I can't write a lot for the first time, and many of them are wrong. The following is the code I wrote for your reference:
#! / bin/bash
Date_b= `date "+% m%d%H" `
Date_c= `date-d "1 day ago" +% m% d% H`
# ip= `cat / etc/network/interfaces | grep address | awk'{print $2}'| grep-v-E "^ 192 | ^ 127" `
#
For c in `cat / etc/network/interfaces | grep address | awk'{print $2}'| grep-v-E "^ 192 | ^ 127" `
Do
/ bin/netstat-na | grep "$print 22" | awk'{print $5}'| awk-F ":"'{print $1}'| sort | uniq-c | sort-n-r > > iptabsh.txt
For i in `awk'$1 > 5 {print $2} 'iptabsh.txt`
Do
A = `grep "^ $i$" ipallow.txt | wc-l`
If [$a-eq 0]
Then
Echo "$I" > > sh$date_b.txt
Iptables-I INPUT-s "$I"-p tcp-- dport 22-j DROP
Fi
Done
Done
Rm iptabsh.txt
# # #
If [- f sh$date_c.txt]
Then
For i in `cat sh$date_ c.txt`
Do
Iptables-D INPUT-s "$I"-p tcp-- dport 22-j DROP
Done
Fi
Many of them do not set the absolute path, you can set the absolute path according to your storage location.