mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
ssh aruba
This commit is contained in:
parent
e91c8e4143
commit
7f87df20c2
@ -12,7 +12,6 @@ from datetime import timedelta
|
|||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.helpers import validate_config
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
@ -45,6 +44,7 @@ def get_scanner(hass, config):
|
|||||||
|
|
||||||
class ArubaDeviceScanner(object):
|
class ArubaDeviceScanner(object):
|
||||||
""" This class queries a Aruba Acces Point for connected devices. """
|
""" This class queries a Aruba Acces Point for connected devices. """
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.host = config[CONF_HOST]
|
self.host = config[CONF_HOST]
|
||||||
self.username = config[CONF_USERNAME]
|
self.username = config[CONF_USERNAME]
|
||||||
@ -97,10 +97,10 @@ class ArubaDeviceScanner(object):
|
|||||||
|
|
||||||
import pexpect
|
import pexpect
|
||||||
connect = "ssh {}@{}"
|
connect = "ssh {}@{}"
|
||||||
ssh = pexpect.spawn (connect.format(self.username, self.host))
|
ssh = pexpect.spawn(connect.format(self.username, self.host))
|
||||||
query = ssh.expect(['password:',pexpect.TIMEOUT,pexpect.EOF,'continue connecting (yes/no)?',
|
query = ssh.expect(['password:', pexpect.TIMEOUT, pexpect.EOF, 'continue connecting (yes/no)?',
|
||||||
'Host key verification failed.','Connection refused','Connection timed out'],timeout=120)
|
'Host key verification failed.', 'Connection refused', 'Connection timed out'], timeout=120)
|
||||||
if query == 1:
|
if query == 1:
|
||||||
_LOGGER.error("Timeout")
|
_LOGGER.error("Timeout")
|
||||||
return
|
return
|
||||||
elif query == 2:
|
elif query == 2:
|
||||||
@ -108,23 +108,23 @@ class ArubaDeviceScanner(object):
|
|||||||
return
|
return
|
||||||
elif query == 3:
|
elif query == 3:
|
||||||
ssh.sendline('yes')
|
ssh.sendline('yes')
|
||||||
ssh.expect ('password:')
|
ssh.expect('password:')
|
||||||
elif query == 4:
|
elif query == 4:
|
||||||
_LOGGER.error("Host key Changed")
|
_LOGGER.error("Host key Changed")
|
||||||
return
|
return
|
||||||
elif query == 5:
|
elif query == 5:
|
||||||
#_LOGGER.error("Connection refused by server")
|
_LOGGER.error("Connection refused by server")
|
||||||
return
|
return
|
||||||
elif query == 6:
|
elif query == 6:
|
||||||
#_LOGGER.error("Connection timed out")
|
_LOGGER.error("Connection timed out")
|
||||||
return
|
return
|
||||||
ssh.sendline (self.password )
|
ssh.sendline(self.password)
|
||||||
ssh.expect ('#')
|
ssh.expect('#')
|
||||||
ssh.sendline ('show clients')
|
ssh.sendline('show clients')
|
||||||
ssh.expect ('#')
|
ssh.expect('#')
|
||||||
devices_result = ssh.before.split(b'\r\n')
|
devices_result = ssh.before.split(b'\r\n')
|
||||||
ssh.sendline ('exit')
|
ssh.sendline('exit')
|
||||||
|
|
||||||
devices = {}
|
devices = {}
|
||||||
for device in devices_result:
|
for device in devices_result:
|
||||||
match = _DEVICES_REGEX.search(device.decode('utf-8'))
|
match = _DEVICES_REGEX.search(device.decode('utf-8'))
|
||||||
@ -133,5 +133,5 @@ class ArubaDeviceScanner(object):
|
|||||||
'ip': match.group('ip'),
|
'ip': match.group('ip'),
|
||||||
'mac': match.group('mac').upper(),
|
'mac': match.group('mac').upper(),
|
||||||
'name': match.group('name')
|
'name': match.group('name')
|
||||||
}
|
}
|
||||||
return devices
|
return devices
|
||||||
|
Loading…
x
Reference in New Issue
Block a user