Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Commit

Permalink
Merge 5aee6a9 into 094a60d
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic committed May 31, 2017
2 parents 094a60d + 5aee6a9 commit a7c0bd9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions napalm_ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import re
import os
import uuid
import socket
import tempfile

from netmiko import ConnectHandler, FileTransfer, InLineTransfer
Expand Down Expand Up @@ -145,6 +146,18 @@ def _send_command(self, command):

def is_alive(self):
"""Returns a flag with the state of the SSH connection."""
null = chr(0)
try:
# Try sending ASCII null byte to maintain
# the connection alive
self.device.send_command(null)
except (socket.error, EOFError):
# If unable to send, we can tell for sure
# that the connection is unusable,
# hence return False.
return {
'is_alive': False
}
return {
'is_alive': self.device.remote_conn.transport.is_active()
}
Expand Down

0 comments on commit a7c0bd9

Please sign in to comment.