Python SSH Connection

Hello,
I want to connect like this but

Traceback (most recent call last):
   File "/Users/mkuk/Desktop/pythonProjects/openVas/main.py", line 10, in <module>
     gmp.authenticate("admin", "admin")
   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gvm/protocols/gmpv208/system/authentication.py", line 68, in authenticate
     self._send(cmd.to_string())
   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gvm/protocols/base.py", line 72, in _send
     self._connection.send(data)
   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gvm/connections.py", line 391, in send
     return self._send_all(data)
   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gvm/connections.py", line 217, in _send_all
     sent = self._stdin.channel.send(data)
   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/channel.py", line 801, in send
     return self._send(s, m)
   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/channel.py", line 1198, in _send
     raise socket.error("Socket is closed")
OSError: Socket is closed

Iā€™m getting an error like this

code:

from gvm.connections import SSHConnection
from gvm.protocols.gmpv208 import Gmp
from gvm.transforms import EtreeTransform
from gvm.xml import pretty_print

connection = SSHConnection(hostname='172.16.x.x',username='admin',password='xxx', port=22)

transform = EtreeTransform()
with Gmp(connection, transform=transform) as gmp:
    gmp.authenticate("admin", "admin")
    version = gmp.get_version()
    pretty_print(version)

Hi,

first of all please always quote you code and output with three backticks ```. I updated your post accordingly.

Second, you can only use the SSHConnection out of the box with our products. For using it with a Community Edition based version, you need to setup a SSH server to forward the SSH connection to gvmd.

2 Likes

hi,

thank u.
I solved the problem with unix connection. I can create a task and start it, but how can I monitor the task with Python, that is, how can I give information as a percentage and then get the report?

You need to request the task or report information in a loop. The percentage is included in the responses.

1 Like