当前位置: 首页 > 编程笔记 >

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

陆浩博
2023-03-14
本文向大家介绍Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查),包括了Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查)的使用技巧和注意事项,需要的朋友参考一下

说明:大家平时对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脚本实现防止国外ip访问服务器,包括了Shell脚本实现防止国外ip访问服务器的使用技巧和注意事项,需要的朋友参考一下 客户的要求,不想让外国的ip来访问服务器,本来要让机房在上端路由解决,但是那些人不鸟你!!!~~~~ 这样的话,只能自己用iptables解决了~~~~~~~~~ 关于 ip库  大家可以去 http://www.ipdeny.com/ipblocks/ 

  • 本文向大家介绍Vue 使用beforeEach实现登录状态检查功能,包括了Vue 使用beforeEach实现登录状态检查功能的使用技巧和注意事项,需要的朋友参考一下 使用VueRouter的beforeEach钩子函数,可以实现导航跳转前检查登录状态的需求。 1.在登录请求接口时返回用户的信息,比如 userInfo:{userId:'123', userName:'小明'},登录成功之后将us

  • 本文向大家介绍阿里云windows服务器安全设置(防火墙策略),包括了阿里云windows服务器安全设置(防火墙策略)的使用技巧和注意事项,需要的朋友参考一下 通过防火墙策略限制对外扫描行为 请您根据您的服务器操作系统,下载对应的脚本运行,运行后您的防火墙策略会封禁对外发包的行为,确保您的主机不会再出现恶意发包的情况,为您进行后续数据备份操作提供足够的时间。 Window2003的批处理文件 Wi

  • 熟悉防火墙的都知道,防火墙一般放在网关上,用来隔离子网之间的访问。因此,防火墙即服务(FireWall as a Service)也是在网络节点上(具体说来是在路由器命名空间中)来实现。 目前,OpenStack 中实现防火墙还是基于 Linux 系统自带的 iptables,所以大家对于其性能和功能就不要抱太大的期望了。 一个可能混淆的概念是安全组(Security Group),安全组的对象是

  • 本文向大家介绍一键配置CentOS iptables防火墙的Shell脚本分享,包括了一键配置CentOS iptables防火墙的Shell脚本分享的使用技巧和注意事项,需要的朋友参考一下 手里几台VPS配置iptables太繁琐,看到了朱哥的LNMP脚本里有一个自动配置iptables防火墙的脚本,借来改了一下,给需要的人用; 只提供常用端口的设置,如果你有特殊需求只需自行添加或减少相应的端口

  • 我怎样才能禁用Debian的保护来允许外部玩家加入我的服务器?