通过python的SoftLayer API Nessus扫描状态/报告

2024-03-28 18:36:34 发布

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

我想使用python客户端创建一个Nessus安全扫描程序,并通过getStatus检查状态,通过getReport方法得到结果。同时,我已经阅读了php(SoftLayer API Nessus Scan Status / Report via PHP)提供的这些帮助。但是python客户端如何使用这些呢? 在python调用setInitParameter(scan\u id)时,异常如下: SoftLayerAPIError(客户端):函数(“setInitParameter”)不是此服务的有效方法


Tags: 方法程序reportapi客户端scan状态status
1条回答
网友
1楼 · 发布于 2024-03-28 18:36:34

我建议您先阅读客户的文档:

https://github.com/softlayer/softlayer-pythonhttps://softlayer-api-python-client.readthedocs.io/en/latest/

init参数设置如下:

clientService.getObject(id=myInitParameter)

在这里,您可以找到更多使用客户端的示例:

https://softlayer.github.io/python/

您可以在此处找到其他文档:

http://sldn.softlayer.com/blog

记住,与php客户端不同,Softlayer的python客户端以json格式发送数据,因此请求:

$client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);

    $accountInfo = $client->getObject();
    $hardware = $client->getHardware();

    foreach ($hardware as $server){
        $scanclient = SoftLayer_SoapClient::getClient('SoftLayer_Network_Security_Scanner_Request', '', $apiUsername, $apiKey)  



$scantemplate = new stdClass();
    $scantemplate->accountId = $accountInfo->id;
    $scantemplate->hardwareId = $server->id;
    $scantemplate->ipAddress = $server->primaryIpAddress;
    try{
            // Successfully creates new scan
            $scan = $scanclient->createObject($scantemplate);
    } catch (Exception $e){
            echo $e->getMessage() . "\n\r";
    }

会是这样的:

clientAccount = client['SoftLayer_Account']
accountInfo = clientAccount.getObject()   #for this case we do not need init parameter
hardware = clientAccount.getHardware()    #for this case we do not need init parameter

for server in hardware:

    scanclient = client['SoftLayer_Network_Security_Scanner_Request']

    scantemplate = {
       "accountId": accountInfo["id"],
       "hardwareId": server["id"],
      "ipAddress": server["primaryIpAddress"]
   }

   scanclient.createObject(scantemplate) 

相关问题 更多 >