濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Shell腳本實(shí)現(xiàn)檢查服務(wù)器安全狀態(tài)(用戶、登錄IP、防火墻檢查)

Shell腳本實(shí)現(xiàn)檢查服務(wù)器安全狀態(tài)(用戶、登錄IP、防火墻檢查)

熱門(mén)標(biāo)簽:佛山高德地圖標(biāo)注中心 旅游地圖標(biāo)注大全 地圖標(biāo)注超出范圍怎么辦 百度地圖的地圖標(biāo)注 東莞電銷(xiāo)機(jī)器人價(jià)格一覽表 excel地址地圖標(biāo)注 杭州機(jī)器人外呼系統(tǒng) 百度地圖標(biāo)注圖標(biāo)更換 陜西電銷(xiāo)卡外呼系統(tǒng)怎么安裝

說(shuō)明:大家平時(shí)對(duì)Linux服務(wù)器安全主要是對(duì)系統(tǒng)用戶的檢查,登陸服務(wù)器IP檢查,以及防火墻狀態(tài)檢查!

1.需要把正確系統(tǒng)用戶名存儲(chǔ)在/root/liu_shell/local_user.txt文件中,然后進(jìn)行比較!
2.對(duì)登陸IP判斷是不是以192.168.1和192.168.2開(kāi)頭的IP為正常IP!
3.判斷iptables狀態(tài)!

復(fù)制代碼 代碼如下:
 
#!/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腳本監(jiān)控服務(wù)器在線狀態(tài)和郵件報(bào)警的方法
  • linux服務(wù)器安全加固shell腳本代碼
  • 用shell+sendmail實(shí)現(xiàn)服務(wù)器監(jiān)控報(bào)警小腳本
  • shell腳本從SVN推送到多臺(tái)服務(wù)器的代碼
  • 使用xp_cmdshell注銷(xiāo)Windows登錄用戶(終端服務(wù)器超出最大連接數(shù))

標(biāo)簽:青島 隨州 延邊 雅安 南充 朝陽(yáng) 西藏 通遼

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Shell腳本實(shí)現(xiàn)檢查服務(wù)器安全狀態(tài)(用戶、登錄IP、防火墻檢查)》,本文關(guān)鍵詞  Shell,腳本,實(shí)現(xiàn),檢查,服務(wù)器,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Shell腳本實(shí)現(xiàn)檢查服務(wù)器安全狀態(tài)(用戶、登錄IP、防火墻檢查)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于Shell腳本實(shí)現(xiàn)檢查服務(wù)器安全狀態(tài)(用戶、登錄IP、防火墻檢查)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    通化县| 临沭县| 甘肃省| 连山| 永春县| 临夏县| 瓮安县| 揭西县| 高阳县| 兴山县| 盱眙县| 资阳市| 罗平县| 健康| 类乌齐县| 巩留县| 安岳县| 慈利县| 基隆市| 台北市| 鄂伦春自治旗| 靖西县| 汾西县| 吴堡县| 山东省| 尉犁县| 凤城市| 姚安县| 怀化市| 台中市| 铁力市| 郑州市| 六枝特区| 黔西| 元朗区| 扬州市| 湟中县| 临颍县| 沧源| 蓬溪县| 涞水县|