国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Linux Shell > 正文

Shell腳本實現檢查服務器安全狀態(用戶、登錄IP、防火墻檢查)

2020-07-27 19:11:31
字體:
來源:轉載
供稿:網友

說明:大家平時對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()

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博客| 迭部县| 措勤县| 崇州市| 和林格尔县| 大宁县| 奉贤区| 克拉玛依市| 大洼县| 六盘水市| 报价| 河津市| 新巴尔虎右旗| 麦盖提县| 阿鲁科尔沁旗| 清涧县| 洛南县| 嘉善县| 图木舒克市| 商洛市| 四平市| 万盛区| 化隆| 清丰县| 嘉黎县| 普陀区| 武汉市| 石棉县| 越西县| 合川市| 万荣县| 雷山县| 金湖县| 宁城县| 白朗县| 成安县| 大兴区| 岢岚县| 工布江达县| 防城港市| 怀远县|