2012-02-07 110 views
0

返回變量我寫這個劇本與Nessus的互動,並告訴我,報告是在Nessus的列表:如何分析和蟒蛇

#!/usr/bin/python 
from NessusXMLRPC import Scanner 
import sys 
x = Scanner("localhost", "8834", login="root", password="password123") 
report = str(x.reportList()) 
print report 
x.logout 

我現在想借此輸出:

[email protected]:~/NessusXMLRPC-0.21# ./reportfornessus.py 
[{'status': 'running', 'readableName': 'SecondScan', 'name': '76c25e9b-8280-5310-23e8-f9873255c5a6288ff86b03b2cdb6', 'timestamp': '1328641639'}, {'status': 'running', 'readableName': 'Third Scan', 'name': '01b2a026-44d3-574c-08e3-e6c97e3f8e21c7c00ec9cb71a7cd', 'timestamp': '1328641704'}] 

並通過它進行解析,尋找我特別通過的「可讀名稱」,然後返回該掃描的「狀態」。

+2

你不清楚如何使用列表和字典?你需要找一個教程嗎?這些內容在大多數教程中都有詳細介紹。你一直在使用什麼來學習Python? – 2012-02-07 19:21:10

回答

4
scn = Scanner("localhost", "8834", login="root", password="password123") 
reports = scn.reportList() 
for r in reports: 
    if r["readableName"] == SOME_NAME: 
     print r["status"] 
+0

打我吧,哈哈... – jyore 2012-02-07 19:24:36

+0

非常感謝。 r [「X」]是否指示結果? – 2012-02-07 19:29:56

+2

@ S-Ns-3:你應該真的閱讀一個Python教程。 – 2012-02-07 19:32:42