Skip to content

Commit

Permalink
Updated remote
Browse files Browse the repository at this point in the history
  • Loading branch information
z1pti3 committed Oct 23, 2021
1 parent c0b40e1 commit 959020a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
39 changes: 10 additions & 29 deletions includes/cisco.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,27 @@

class cisco(remote.remote):

def __init__(self, host, deviceHostname, username="Admin", password='', enablePassword="", port=22, timeout=5, attempts=3):
def __init__(self, host, deviceHostname, username="Admin", password='', enablePassword="", port=22, timeout=5):
self.host = host
self.deviceHostname = deviceHostname
self.timeout = timeout
self.enablePassword = enablePassword
self.error = ""
self.type = "cisco"
for x in range(1,attempts):
self.client = self.connect(username,password,port)
if self.client:
break
time.sleep(timeout)
self.client = self.connect(username,password,port,timeout)

def connect(self,username,password,port):
def connect(self,username,password,port,timeout):
try:
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(AutoAddPolicy())
try:
client.connect(self.host, username=username, password=password, port=port, look_for_keys=True, timeout=self.timeout,banner_timeout=60)
client.connect(self.host, username=username, password=password, port=port, look_for_keys=True, timeout=timeout,banner_timeout=timeout)
except ssh_exception.SSHException:
time.sleep(2)
client.connect(self.host, username=username, password=password, port=port, look_for_keys=True, timeout=self.timeout,banner_timeout=60)
time.sleep(timeout)
client.connect(self.host, username=username, password=password, port=port, look_for_keys=True, timeout=timeout,banner_timeout=timeout)
self.channel = client.invoke_shell()
if not self.recv():
startTime = time.time()
detectedDevice = ""
while ( time.time() - startTime < self.timeout ):
self.command("")
if self.channel.recv_ready():
detectedDevice += self.channel.recv(2048).decode().strip()
time.sleep(0.5)
self.error = f"Device detected name does not match the device name provided. Hostname found = {detectedDevice}"
if not self.recv(timeout):
self.error = "Device detected name does not match the device name provided."
client.close()
return None
return client
Expand Down Expand Up @@ -77,7 +65,7 @@ def awaitStringRecv(self,awaitString,timeout=5):
return recvBuffer
return False

def recv(self,timeout=5,attempt=0):
def recv(self,timeout=5):
startTime = time.time()
deviceHostname = self.deviceHostname
if len(deviceHostname) >= 20:
Expand All @@ -96,16 +84,9 @@ def recv(self,timeout=5,attempt=0):
time.sleep(0.1)
if result:
return recvBuffer
elif attempt < 3:
attempt += 1
self.channel.send(" ")
recvData = self.recv(timeout,attempt)
if recvData:
recvBuffer += recvData
return recvBuffer
return False

def sendCommand(self,command,attempt=0):
def sendCommand(self,command):
self.channel.send("{0}{1}".format(command,"\n"))
time.sleep(0.5)
return True
Expand Down
4 changes: 2 additions & 2 deletions includes/fortigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def recv(self,timeout):
time.sleep(0.1)
return recvBuffer

def sendCommand(self,command,attempt=0):
sentBytes = self.channel.send("{0}{1}".format(command,"\n"))
def sendCommand(self,command):
self.channel.send("{0}{1}".format(command,"\n"))
time.sleep(0.5)
return True

Expand Down

0 comments on commit 959020a

Please sign in to comment.