当前位置: 移动技术网 > 网络运营>服务器>Linux > Shell脚本实现非法IP登陆自动报警

Shell脚本实现非法IP登陆自动报警

2017年12月12日  | 移动技术网网络运营  | 我要评论

服务器的安全稳定是每个运维都希望达到的目标,毕竟网站一旦流量大了,访问高了,就会有一些无聊人来攻击,帮忙检测漏洞是好,但纯ddos的性质就很恶劣了.说远了,这篇文章只是检测有非法ip登录到服务器上就自动给运维报警,当然也可以改成短信报警,前提是你有短信网关.

复制代码 代码如下:

#!/bin/bash
#该脚本作用是检测是否有恶意ip登陆服务器并邮件报警
#可以结合139邮箱以达到短信及时通知到手机的功能
#适用系统centos5
 
ldate=`which date`
lawk=`which awk`
llast=`which last`
lgrep=`which grep`
lsendmail=`which sendmail`
lifconfig=`which ifconfig`
serverip=`$lifconfig eth0|$lgrep inet|$lawk -f : '{print $2}'|$lawk '{print $1}'`
cutdate=`$ldate |$lawk '{print $1" "$2" "$3}'`
 
hackerip=`$llast|$lgrep "$cutdate"|$lawk '{print $3}'|$lgrep -v 192.168.1x.xx`
 
if [ -z $hackerip ]
then
exit
else
 
for logip in $hackerip
do
echo "hacker ip is  $logip already login  $serverip"|mail -s "sos" rocdk890@139.com
 
done
fi

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网