主页 > 知识库 > Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查)

Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查)

热门标签:佛山高德地图标注中心 旅游地图标注大全 地图标注超出范围怎么办 百度地图的地图标注 东莞电销机器人价格一览表 excel地址地图标注 杭州机器人外呼系统 百度地图标注图标更换 陕西电销卡外呼系统怎么安装

说明:大家平时对Linux服务器安全主要是对系统用户的检查,登陆服务器IP检查,以及防火墙状态检查!

1.需要把正确系统用户名存储在/root/liu_shell/local_user.txt文件中,然后进行比较!
2.对登陆IP判断是不是以192.168.1和192.168.2开头的IP为正常IP!
3.判断iptables状态!

复制代码 代码如下:
 
#!/usr/bin/python
#coding=utf-8
import sys,os,re,socket
host=str(socket.gethostname().strip())
fuhao=os.linesep
def user_panduan():
    file01=file('/etc/passwd')
    mmm=[]
    for xx in file01:
        mmm.append(re.split(':',xx)[0])
    file01.close()
    file02=file('/root/liu_shell/new_user.txt','w')
    for yy in mmm:
        file02.write('%s%s' %(yy,fuhao))
    file02.close()
    f_local=file('/root/liu_shell/local_user.txt')
    f_new=file('/root/liu_shell/new_user.txt')
    local_user=[]
    new_user=[]
    for line1 in f_local:
        line1=line1.strip()
        local_user.append(line1)
    for line2 in f_new:
        line2=line2.strip()
        new_user.append(line2)
    f_local.close()
    f_new.close()
    if local_user==new_user:
        print 'host:%s user ok' %host
    else:
        cmd="echo 'host:%s user error' |mail -s  user_error 331095659@qq.com " %host
        os.system(cmd)
def ip_panduan():
    os.system("last|awk '{print $3}'|grep -v [a-z]|grep -v ^$|sort |uniq >/root/liu_shell/local_ip.txt")
    f_ip=file('/root/liu_shell/local_ip.txt')
    local_ip=[]
    for line in f_ip:
        line=line.strip()
        local_ip.append(line)
    for aa in local_ip:
        kk=re.match('192.168.1|192.168.2',aa)
        if kk:
            print 'host:%s ip ok' %host
        else:
            cmd="echo 'host:%s ip error' |mail -s  ip_error 331095659@qq.com " %host
            os.system(cmd)
def iptables_panduan():
    iptables_status=int(os.popen("/sbin/iptables -nL|grep -v ^$|wc -l").readline().strip())
    if iptables_status==6:
        cmd="echo 'host:%s iptables not running!' |mail -s  iptables 331095659@qq.com " %host
        os.system(cmd)
    else:
        print 'host:%s iptable running ok' %host
user_panduan()
ip_panduan()
iptables_panduan()

您可能感兴趣的文章:
  • Shell脚本监控服务器在线状态和邮件报警的方法
  • linux服务器安全加固shell脚本代码
  • 用shell+sendmail实现服务器监控报警小脚本
  • shell脚本从SVN推送到多台服务器的代码
  • 使用xp_cmdshell注销Windows登录用户(终端服务器超出最大连接数)

标签:青岛 随州 延边 雅安 南充 朝阳 西藏 通辽

巨人网络通讯声明:本文标题《Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查)》,本文关键词  Shell,脚本,实现,检查,服务器,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查)》相关的同类信息!
  • 本页收集关于Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查)的相关信息资讯供网民参考!
  • 推荐文章