Gvm-script get port lists

GVM versions

Greenbone Security Assistant 21.4.1~dev1
Greenbone Vulnerability Manager 21.4.2
OpenVAS 21.4.1
gvm-libs 21.4.1


Linux kali 5.10.0-kali7-amd64 #1 SMP Debian 5.10.28-1kali1 (2021-04-12) x86_64 GNU/Linux
Installed GVM using app manager
Installed gvm-tools using pip

The problem that i am having is retreving a list of all my port lists that i have using a script.
I know that I can manualy do it but i am looking for an automated solution so that my scrips can be integrated into another program.

So far i have used “responce = gmp.get_port_lists()”
But the result from printing responce is “<Element get_port_lists_response at 0x7f820c533200>”
and it i try doing “print(responce.get(‘name’))” i get the result “None”

I am assuming that i am using the comands incorrectly but i am simply looking to return each port list name and id so that i can save/use them elseware.

Any help would be much apreciated, thanks.

The response is an xml-Tree.

You can try to import from gvm.xml import pretty_print and use pretty_print(responce) to get familiar with the structure of that xml.

It is “response” and not “responce” by the way.

Quick example from me:

(.venv) bash-3.2$ gvm-pyshell --gmp-username=xxx --gmp-password=xxx ssh --hostname foo.bar.baz
GVM Interactive Console 21.6.2.dev1 API 21.6.0. Type "help" to get information about functionality.
>>> from gvm.xml import pretty_print
>>> response = gmp.get_port_lists()
>>> pretty_print(response)
<get_port_lists_response status="200" status_text="OK">
  <port_list id="1a7539e0-13fa-4a90-9110-178bf0dc8681">
  <port_lists start="1" max="-2"/>
>>> lists = response.findall('port_list')
>>> for list in lists:
...   print(list.find('name').text)
All IANA assigned TCP
All IANA assigned TCP and UDP
All privileged TCP
All privileged TCP and UDP
All TCP and Nmap top 100 UDP
All TCP and Nmap top 1000 UDP
Example-List (0)
Example-List (1)
Example-List (2)
Example-List (3)
Example-List (4)
Example-List (5)
Example-List (6)
Example-List (7)
Nmap top 2000 TCP and top 100 UDP
OpenVAS Default
>>> for list in lists:
...   print(list.get('id'))
1 Like

thank you very much this has helped me greatly so that i can get the information extracted.

Also, it seems that i was also misunderstanding the get / find function and where to use it. Hence, getting a “none” result. Thank you for the help