如何通过pyTenable库批量编辑Tenable.sc资产?

2024-10-03 13:25:19 发布

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

利用PyTenable库,我试图找出更改所有可用资产名称的最佳方法,方法是删除所有空格并替换为下划线。例如,将“资产1”更改为“资产1”,然后迭代到下一个资产并执行相同的操作

这是我引用代码的链接-https://pytenable.readthedocs.io/en/stable/sc.html#asset-lists

我开始使用的方法是编辑方法,我在这里使用的方法如下:

from tenable.sc import TenableSC

#Login
sc = TenableSC('0.0.0.0',username='user1',password='pass1')

#Rename the asset with ID 1
asset1 = sc.asset_lists.edit(1, name='Renamed_Asset1')

#Display the asset with the new name
print(asset1)

sc.logout()

我知道可以用下划线替换空格,但我不确定如何将函数作为输入传递给可成立的实例:

def replace_empty(name):
name.replace(" ", "_")

返回的输出是字典格式的,但是我认为这并不重要,因为我正在向资产的name-key:value对发送对单个值的更改

使用的可成立的方法将在此链接中-https://docs.tenable.com/tenablesc/api/Asset.htm

有人知道如何迭代地更改所有资产吗


Tags: the方法namehttps链接with资产asset