Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Allow to connect to the device on a non-standard port #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow to connect to the device on a non-standard port
Brian Gannon authored and Brian Gannon committed Mar 8, 2018
commit 3eac13a00fbad218ae0ecb0a4720c1f36385c721
9 changes: 7 additions & 2 deletions pyFG/fortios.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@

class FortiOS(object):

def __init__(self, hostname, vdom=None, username=None, password=None, keyfile=None, timeout=60):
def __init__(self, hostname, vdom=None, username=None, password=None, keyfile=None, timeout=60, port=22):
"""
Represents a device running FortiOS.

@@ -45,6 +45,7 @@ def __init__(self, hostname, vdom=None, username=None, password=None, keyfile=No
* **password** (str) -- Username password
* **keyfile** (str) -- Path to the private key in case you want to use this authentication method.
* **timeout** (int) -- Time in seconds to wait for the device to respond.
* **port** (int) -- Port of the device you want to connect.

"""
self.hostname = hostname
@@ -57,6 +58,7 @@ def __init__(self, hostname, vdom=None, username=None, password=None, keyfile=No
self.password = password
self.keyfile = keyfile
self.timeout = timeout
self.port = port

# Set key exchange explcitly to address known fortinet issue
paramiko.Transport._preferred_kex = ('diffie-hellman-group14-sha1',
@@ -80,7 +82,8 @@ def open(self):
'timeout': self.timeout,
'username': self.username,
'password': self.password,
'key_filename': self.keyfile
'key_filename': self.keyfile,
'port': self.port
}

if os.path.exists(os.path.expanduser("~/.ssh/config")):
@@ -99,6 +102,8 @@ def open(self):
cfg['key_filename'] = host_conf['identityfile']
if 'hostname' in host_conf:
cfg['hostname'] = host_conf['hostname']
if 'port' in host_conf:
cfg['port'] = int(host_conf['port'])

self.ssh.connect(**cfg)