def is_ssh_enabled(conn: BaseConnection, device_name: str) -> bool:
    prompt = f"{device_name}#"
    sh_ip_ssh_output = conn.send_command("sh ip ssh", expect_string=prompt)
    if "SSH Enabled - version 2.0" in sh_ip_ssh_output:
        return True
    else:
        return False
Example #2
0
 def __init__(self, *args, **kwargs):
     """
     Constructor of the SSHDetect class
     """
     if kwargs["device_type"] != "autodetect":
         raise ValueError("The connection device_type must be 'autodetect'")
     self.connection = ConnectHandler(*args, **kwargs)
     # Call the _test_channel_read() in base to clear initial data
     output = BaseConnection._test_channel_read(self.connection)
     self.initial_buffer = output
     self.potential_matches = {}
     self._results_cache = {}
Example #3
0
 def __init__(self, *args: Any, **kwargs: Any) -> None:
     """
     Constructor of the SSHDetect class
     """
     if kwargs["device_type"] != "autodetect":
         raise ValueError("The connection device_type must be 'autodetect'")
     # Always set cmd_verify to False for autodetect
     kwargs["global_cmd_verify"] = False
     self.connection = ConnectHandler(*args, **kwargs)
     # Call the _test_channel_read() in base to clear initial data
     output = BaseConnection._test_channel_read(self.connection)
     self.initial_buffer = output
     self.potential_matches: Dict[str, int] = {}
     self._results_cache: Dict[str, str] = {}
Example #4
0
def search_mac():
    device_params = {
        'device_type': 'linux',
        'ip': '',
        'username': '',
        'password': '',
        'session_log': "output.txt",
    }
    s_ip = str(input("Введите ip: "))
    print('Ищу mac-adress устройства.')
    with BaseConnection(**device_params) as ssh:
        ssh.send_command('cd /var/log')
        result = ssh.send_command(
            'grep -i "{} to ..:..:..:..:..:.." dhcpd.log | tail -1'.format(
                s_ip))
        mac_addres = re.search(r'([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}', result)
        mac_addres = mac_addres.group()
        print("MAC-adress: {}".format(mac_addres))
    return mac_addres
def test_strip_backspaces():
    """Strip any backspace characters out of the output"""
    text = "Writing\x08something\x08"
    output = BaseConnection.strip_backspaces(text)
    assert output == "Writingsomething"
Example #6
0
def test_strip_backspaces():
    """Strip any backspace characters out of the output"""
    text = "Writing\x08something\x08"
    output = BaseConnection.strip_backspaces(text)
    assert output == "Writingsomething"
Example #7
0
 def __init__(self, **kwargs):
     kwargs['device_type'] = 'ibmnos_telnet'
     BaseConnection.__init__(self, **kwargs)