Skip to content

Commit

Permalink
Updated device detection
Browse files Browse the repository at this point in the history
  • Loading branch information
z1pti3 committed Aug 22, 2021
1 parent 41261c5 commit 43f34b5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions includes/cisco.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ def connect(self,username,password,port):
self.channel = client.invoke_shell()
if not self.recv():
self.command("")
time.sleep(0.5)
startTime = time.time()
detectedDevice = ""
while ( time.time() - startTime < 5 ):
if self.channel.recv_ready():
detectedDevice = self.channel.recv(len(self.deviceHostname)+2).decode().strip()
detectedDevice = self.channel.recv(2048).decode().strip()
time.sleep(0.1)
self.error = f"Device detected name does not match the device name provided. Hostname found = {detectedDevice}"
client.close()
return None
Expand Down Expand Up @@ -86,7 +88,7 @@ def recv(self,timeout=5,attempt=0):
if recvBuffer.split('\n')[-1].endswith("--More--"):
self.channel.send(" ")
recvBuffer = recvBuffer[:-8]
elif recvBuffer.split('\n')[-1].startswith(deviceHostname):
elif recvBuffer.split('\n')[-1].lower().startswith(deviceHostname.lower()):
result = True
break
time.sleep(0.1)
Expand Down Expand Up @@ -118,7 +120,11 @@ def sendCommand(self,command,attempt=0):

def command(self, command, args=[], elevate=False, runAs=None, timeout=5):
if command == "enable":
return (0, self.enable(self.enablePassword), "")
enableResult = self.enable(self.enablePassword)
if enableResult:
return (0, enableResult, "")
else:
return (None, enableResult, "")
elif command == "copy running-config startup-config":
returnedData = ""
self.sendCommand(command)
Expand Down

0 comments on commit 43f34b5

Please sign in to comment.