I’am new to Python things, so maybe a noob question, but I am stucking on it for hours now:
I want to create a new scan target using the gvm-pyshell in Linux.
Creating it without the port_list tag works fine:
gmp.create_target(“TARGETNAME”, True, hosts=“192.168.1.0/24”)
But I want to use a specific port configuration, id: “4a4717fe-57d2-11e1-9a26-406186ea4fc5”
My first tought was, try it like this:
gmp.create_target(“TARGETNAME”, True, hosts=‘192.168.1.0/24’, port_list=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
But then it complains about a missing ID attribute:
ValueError: port_list requires an id attribute
When I try this, it complains about id (but that is logic):
gmp.create_target(“TARGETNAME”, True, hosts=‘192.168.1.0/24’, port_list id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
I’ve tried this:
gmp.create_target(“TARGETNAME”, True, hosts=‘192.168.1.0/24’, port_list_id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
That creates the target, but with the wrong port_list (the openvas default).
I’ve tried too many combinations with (), [], {} and so on, but didn’t find the working one. I think the solution is simple. Hope someone can help me.
gmp.create_target(“TARGETNAME”, make_unique=True, hosts=[‘192.168.1.0/24’], port_list_id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
Traceback (most recent call last):
File “”, line 1, in
File “gmp\gvm_connection.py”, line 328, in create_target
File “gmp\gmp.py”, line 730, in createTargetCommand
File “src\lxml\lxml.etree.pyx”, line 1031, in lxml.etree._Element.text.set (src\lxml\lxml.etree.c:53209)
File “src\lxml\apihelpers.pxi”, line 715, in lxml.etree._setNodeText (src\lxml\lxml.etree.c:24404)
File “src\lxml\apihelpers.pxi”, line 703, in lxml.etree._createTextNode (src\lxml\lxml.etree.c:24267)
File “src\lxml\apihelpers.pxi”, line 1441, in lxml.etree._utf8 (src\lxml\lxml.etree.c:31461)
TypeError: Argument must be bytes or unicode, got ‘list’
GVM Interactive Console 20.10.1 API 1.6.0. Type "help" to get information about functionality.
>>> resp = gmp.create_target("TARGETNAME3", make_unique=True, hosts=['192.168.1.0/24'], port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5")
>>> from gvm.xml import pretty_print
>>> pretty_print(resp)
<create_target_response status="201" status_text="OK, resource created" id="70b6b00c-88a4-410a-9f50-94c5ac0946a4"/>
>>>
What gvm-tools and python-gvm versions are you using?
Just saw, that I have used python-gvm 1.6.0, but it also works with the current release:
GVM Interactive Console 20.10.2.dev1 API 20.11.0. Type "help" to get information about functionality.
>>> resp = gmp.create_target("TARGETNAME2", make_unique=True, hosts=['192.168.1.0/24'], port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5")
>>> resp = gmp.create_target("TARGETNAME4", make_unique=True, hosts=['192.168.1.0/24'], port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5")
>>> pretty_print(resp)
<create_target_response status="201" status_text="OK, resource created" id="63d47d0e-ec55-44fd-90da-4eea738b7455"/>