我的Python鳕鱼跑得不好

2024-09-23 16:32:48 发布

您现在位置:Python中文网/ 问答频道 /正文

第一次来这里,我有一个问题,如果你能解决我,我将非常感谢你们所有人。 我在做一个HIDS项目,我有一个问题,当我在linux(centos6.3)上运行我的代码时,效果很好,但是当我尝试在带有apache的web脚本上运行它时,效果就不太好了。我在Python上的代码

def sniffcometome(userbd,passbd):
    db= mysql.connect("localhost",userbd,passbd,"HIDS")
    cursor = db.cursor()
    proc = subprocess.Popen("ps -eo user | grep -v root | grep -v apache",shell=True,executable='/bin/bash',stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    (out,err) = proc.communicate()
    out = out.split()
    n = len(out)
    print "Content-Type: text/html\r\n\r\n"
    for i in range (n):
            sql = "select program from SNIFFER where program = '%s'"%(out[i])
            #print out[i]
            cursor.execute(sql)
            result = cursor.fetchone()
            if result != None:
                    SendMail('ALERT: Sniffer detected!')
                    print "Content-type: text/html\r\n\r\n"
                    print "Success"
    cursor.close()
    db.close()

    print "Content-type: text/html\n\n"
    print "Success"

当我在Centos上运行时,输出

['USER', 'rpc', 'dbus', 'avahi', 'avahi', 'rpcuser', 'haldaemon', 'haldaemon', 'mysql', 'postfix', 'postfix', 'tcpdump']

当我在APACHE上运行时,只有这个输出

['USER']

谢谢你们!祝你今天愉快!你知道吗


Tags: 代码textdbapachehtmlmysqlcontentout