校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > 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、防火墻檢查)的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 徐汇区| 三门县| 乌苏市| 孝义市| 中宁县| 武隆县| 图们市| 苗栗县| 同德县| 方城县| 开化县| 太原市| 碌曲县| 延川县| 虹口区| 美姑县| 衡水市| 安义县| 永福县| 怀柔区| 汤原县| 洛宁县| 贵阳市| 云霄县| 成都市| 武陟县| 土默特右旗| 兖州市| 桂平市| 铁力市| 平顺县| 乐至县| 福州市| 舞阳县| 江永县| 元氏县| 鸡泽县| 武宁县| 南昌市| 牙克石市| 宁波市|