网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

如何编写Shell脚本实现检查服务器安全状态-创新互联

本篇内容介绍了“如何编写Shell脚本实现检查服务器安全状态”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

成都创新互联的客户来自各行各业,为了共同目标,我们在工作上密切配合,从创业型小企业到企事业单位,感谢他们对我们的要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。专业领域包括网站制作、成都做网站、电商网站开发、微信营销、系统平台开发。

说明:大家平时对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脚本实现检查服务器安全状态”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


新闻标题:如何编写Shell脚本实现检查服务器安全状态-创新互联
本文链接:http://bjjierui.cn/article/gdooo.html

其他资讯