Python находит и заменяет универсальный HOSTID с именем компьютера - PullRequest
0 голосов
/ 24 мая 2018

Мне нужно "HOSTID" для разрешения имени хоста машины.Моя цель - взять эту простую команду, запустить ее вручную в Terminal и сделать ее переносимой в скрипте Python.

Sudo /library.nessusagent.run.sbin.nessuscli agent link -- 
key=5e30508800865f87a8dbe8993fa75d21f9e2acc7db12165050cf48b5ccbafb84 -- 
name=HOSTID --groups=Mac_OS_Systems --Host=Cloud.tenable.com --port=443

Приведенный ниже код даст мне ХОСТИД, как мне указать его в нужном месте?

import platform
platform.node() 

1 Ответ

0 голосов
/ 24 мая 2018

Это должно работать:

import platform, subprocess

# Get the HOSTID
host_id = str(platform.node())

# Make the command string and replace HOSTID with host_id's value
command = "sudo /library.nessusagent.run.sbin.nessuscli agent link -- key=5e30508800865f87a8dbe8993fa75d21f9e2acc7db12165050cf48b5ccbafb84 -- name={0} --groups=Mac_OS_Systems --Host=Cloud.tenable.com --port=443".format(host_id)

# Run the command
execute = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)

# Save the output
out, err = execute.communicate()

# Print the output (assuming there is an output)
print (out)
...