Creating a new target with port_list

Dear,

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.

Thanks :slight_smile:

Looking at the docs and code it should be

gmp.create_target(“TARGETNAME”, make_unique=True, hosts=[‘192.168.1.0/24’], port_list_id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
1 Like

That doesn’t work too.

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’

No Issues here:

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"/>
1 Like

File “gmp\gvm_connection.py”, line 328, in create_target
File “gmp\gmp.py”, line 730, in createTargetCommand

Looks like gvm-tools < 2.0. That version is unsupported and outdated. Please update to the current one.

2 Likes

When I type help it shows up:
gvm-pyshell 1.4.1
I just downloaded the gvm shell from the website (so I guess it’s the latest?)

Don’t know where I can see the gvm-tools version.

What website?
Our packages can be installed with pip, or from source at https://github.com/greenbone/gvm-tools and https://github.com/greenbone/python-gvm.

1 Like

Please follow the documentation here https://gvm-tools.readthedocs.io/en/latest/ You are using gvm-tools 1.4.1 which is very old.

2 Likes

On here: https://docs.greenbone.net/GSM-Manual/gos-5/en/gmp.html
It shows up: Python shell: gvm-pyshell.exe
From there I downloaded the Python shell.

Installed gvm-tools using pip install now, and it works. Thanks for all the replys.

1 Like