简体   繁体   English

如何在python中解析和返回变量

[英]How to parse and return variables in python

I wrote this script to interact with nessus and tell me what reports were in the nessus list: 我编写了此脚本以与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

I now want to take the output: 我现在要输出:

root@bt:~/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'}]

and parse through it looking for my specifically passed 'readableName' and then return the 'status' for that scan. 并通过它进行解析,以查找我专门传递的“ visibleName”,然后返回该扫描的“状态”。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM