desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Retrieve data from Actiontec MI424WR and return parsed result.'
def get_actiontec_data(self):
try: telnet = telnetlib.Telnet(self.host) telnet.read_until('Username: ') telnet.write((self.username + '\n').encode('ascii')) telnet.read_until('Password: ') telnet.write((self.password + '\n').encode('ascii')) prompt = telnet.read_until('Wireless Broadband ...
'Initialize the scanner.'
def __init__(self, config):
from pysnmp.entity.rfc3413.oneliner import cmdgen from pysnmp.entity import config as cfg self.snmp = cmdgen.CommandGenerator() self.host = cmdgen.UdpTransportTarget((config[CONF_HOST], 161)) if ((CONF_AUTHKEY not in config) or (CONF_PRIVKEY not in config)): self.auth = cmdgen.CommunityData(...
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return [client['mac'] for client in self.last_results if client.get('mac')]
'Return the name of the given device or None if we don\'t know.'
def get_device_name(self, device):
return None
'Ensure the information from the device is up to date. Return boolean if scanning successful.'
def _update_info(self):
if (not self.success_init): return False data = self.get_snmp_data() if (not data): return False self.last_results = data return True
'Fetch MAC addresses from access point via SNMP.'
def get_snmp_data(self):
devices = [] (errindication, errstatus, errindex, restable) = self.snmp.nextCmd(self.auth, self.host, self.baseoid) if errindication: _LOGGER.error('SNMPLIB error: %s', errindication) return if errstatus: _LOGGER.error('SNMP error: %s at %s', errstatus.prettyPri...
'Initialize the scanner.'
def __init__(self, config):
self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = config[CONF_PASSWORD] self.last_results = {} self.mac2name = {} url = 'http://{}/Status_Wireless.live.asp'.format(self.host) data = self.get_ddwrt_data(url) if (not data): raise ConnectionError('C...
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return self.last_results
'Return the name of the given device or None if we don\'t know.'
def get_device_name(self, device):
if (device not in self.mac2name): url = 'http://{}/Status_Lan.live.asp'.format(self.host) data = self.get_ddwrt_data(url) if (not data): return None dhcp_leases = data.get('dhcp_leases', None) if (not dhcp_leases): return None cleaned_str = dhc...
'Ensure the information from the DD-WRT router is up to date. Return boolean if scanning successful.'
def _update_info(self):
_LOGGER.info('Checking ARP') url = 'http://{}/Status_Wireless.live.asp'.format(self.host) data = self.get_ddwrt_data(url) if (not data): return False self.last_results = [] active_clients = data.get('active_wireless', None) if (not active_clients): return False clean_s...
'Retrieve data from DD-WRT and return parsed result.'
def get_ddwrt_data(self, url):
try: response = requests.get(url, auth=(self.username, self.password), timeout=4) except requests.exceptions.Timeout: _LOGGER.exception('Connection to the router timed out') return if (response.status_code == 200): return _parse_ddwrt_response(response.text) ...
'Initialize the scanner.'
def __init__(self, config):
self.last_results = [] self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = config[CONF_PASSWORD] self.success_init = True import fritzconnection as fc try: self.fritz_box = fc.FritzHosts(address=self.host, user=self.username, password=self.password) ...
'Scan for new devices and return a list of found device ids.'
def scan_devices(self):
self._update_info() active_hosts = [] for known_host in self.last_results: if ((known_host['status'] == '1') and known_host.get('mac')): active_hosts.append(known_host['mac']) return active_hosts
'Return the name of the given device or None if is not known.'
def get_device_name(self, mac):
ret = self.fritz_box.get_specific_host_entry(mac).get('NewHostName') if (ret == {}): return None return ret
'Retrieve latest information from the FRITZ!Box.'
def _update_info(self):
if (not self.success_init): return False _LOGGER.info('Scanning') self.last_results = self.fritz_box.get_hosts_info() return True
'Initialize the scanner.'
def __init__(self, config):
self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.port = config.get(CONF_PORT) self.password = config.get(CONF_PASSWORD) self.last_results = {} self.success_init = self._update_info() _LOGGER.info('cisco_ios scanner initialized')
'Get the firmware doesn\'t save the name of the wireless device.'
def get_device_name(self, device):
return None
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return self.last_results
'Ensure the information from the Cisco router is up to date. Returns boolean if scanning successful.'
def _update_info(self):
string_result = self._get_arp_data() if string_result: self.last_results = [] last_results = [] lines_result = string_result.splitlines() lines_result = lines_result[2:] for line in lines_result: parts = line.split() if (len(parts) != 6): ...
'Open connection to the router and get arp entries.'
def _get_arp_data(self):
from pexpect import pxssh import re try: cisco_ssh = pxssh.pxssh() cisco_ssh.login(self.host, self.username, self.password, port=self.port, auto_prompt_reset=False) initial_line = cisco_ssh.before.decode('utf-8').splitlines() router_hostname = initial_line[(len(initial_line) ...
'Initialize the scanner.'
def __init__(self, config):
self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = config[CONF_PASSWORD] self.last_results = {} data = self.get_aruba_data() self.success_init = (data is not None)
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return [client['mac'] for client in self.last_results]
'Return the name of the given device or None if we don\'t know.'
def get_device_name(self, device):
if (not self.last_results): return None for client in self.last_results: if (client['mac'] == device): return client['name'] return None
'Ensure the information from the Aruba Access Point is up to date. Return boolean if scanning successful.'
def _update_info(self):
if (not self.success_init): return False data = self.get_aruba_data() if (not data): return False self.last_results = data.values() return True
'Retrieve data from Aruba Access Point and return parsed result.'
def get_aruba_data(self):
import pexpect connect = 'ssh {}@{}' ssh = pexpect.spawn(connect.format(self.username, self.host)) query = ssh.expect(['password:', pexpect.TIMEOUT, pexpect.EOF, 'continue connecting (yes/no)?', 'Host key verification failed.', 'Connection refused', 'Connection timed out'], ti...
'Initialize the scanner.'
def __init__(self, config):
self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = config.get(CONF_PASSWORD, '') self.ssh_key = config.get('ssh_key', config.get('pub_key', '')) self.protocol = config[CONF_PROTOCOL] self.mode = config[CONF_MODE] self.port = config[CONF_PORT] if (self.pro...
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return [client['mac'] for client in self.last_results]
'Return the name of the given device or None if we don\'t know.'
def get_device_name(self, device):
if (not self.last_results): return None for client in self.last_results: if (client['mac'] == device): return client['host'] return None
'Ensure the information from the ASUSWRT router is up to date. Return boolean if scanning successful.'
def _update_info(self):
if (not self.success_init): return False _LOGGER.info('Checking Devices') data = self.get_asuswrt_data() if (not data): return False active_clients = [client for client in data.values() if ((client['status'] == 'REACHABLE') or (client['status'] == 'DELAY') or (client['status'] == ...
'Retrieve data from ASUSWRT and return parsed result.'
def get_asuswrt_data(self):
result = self.connection.get_result() if (not result): return {} devices = {} if (self.mode == 'ap'): for lease in result.leases: match = _WL_REGEX.search(lease.decode('utf-8')) if (not match): _LOGGER.warning('Could not parse wl row: ...
'Return connection state.'
@property def connected(self):
return self._connected
'Mark currenct connection state as connected.'
def connect(self):
self._connected = True
'Mark current connection state as disconnected.'
def disconnect(self):
self._connected = False
'Initialize the SSH connection properties.'
def __init__(self, host, port, username, password, ssh_key, ap):
super(SshConnection, self).__init__() self._ssh = None self._host = host self._port = port self._username = username self._password = password self._ssh_key = ssh_key self._ap = ap
'Retrieve a single AsusWrtResult through an SSH connection. Connect to the SSH server if not currently connected, otherwise use the existing connection.'
def get_result(self):
from pexpect import pxssh, exceptions try: if (not self.connected): self.connect() if self._ap: neighbors = [''] self._ssh.sendline(_WL_CMD) self._ssh.prompt() leases_result = self._ssh.before.split('\n')[1:(-1)] else: ...
'Connect to the ASUS-WRT SSH server.'
def connect(self):
from pexpect import pxssh self._ssh = pxssh.pxssh() if self._ssh_key: self._ssh.login(self._host, self._username, ssh_key=self._ssh_key, port=self._port) else: self._ssh.login(self._host, self._username, password=self._password, port=self._port) super(SshConnection, self).connect()
'Disconnect the current SSH connection.'
def disconnect(self):
try: self._ssh.logout() except Exception: pass finally: self._ssh = None super(SshConnection, self).disconnect()
'Initialize the Telnet connection properties.'
def __init__(self, host, port, username, password, ap):
super(TelnetConnection, self).__init__() self._telnet = None self._host = host self._port = port self._username = username self._password = password self._ap = ap self._prompt_string = None
'Retrieve a single AsusWrtResult through a Telnet connection. Connect to the Telnet server if not currently connected, otherwise use the existing connection.'
def get_result(self):
try: if (not self.connected): self.connect() self._telnet.write('{}\n'.format(_IP_NEIGH_CMD).encode('ascii')) neighbors = self._telnet.read_until(self._prompt_string).split('\n')[1:(-1)] if self._ap: self._telnet.write('{}\n'.format(_WL_CMD).encode('ascii')) ...
'Connect to the ASUS-WRT Telnet server.'
def connect(self):
self._telnet = telnetlib.Telnet(self._host) self._telnet.read_until('login: ') self._telnet.write((self._username + '\n').encode('ascii')) self._telnet.read_until('Password: ') self._telnet.write((self._password + '\n').encode('ascii')) self._prompt_string = self._telnet.read_until('#').sp...
'Disconnect the current Telnet connection.'
def disconnect(self):
try: self._telnet.write('exit\n'.encode('ascii')) except Exception: pass super(TelnetConnection, self).disconnect()
'Initialize the scanner.'
def __init__(self, config):
self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = base64.b64encode(bytes(config[CONF_PASSWORD], 'utf-8')) self.last_results = []
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return [client.mac for client in self.last_results]
'Return the name of the given device or None if we don\'t know.'
def get_device_name(self, device):
if (not self.last_results): return None for client in self.last_results: if (client.mac == device): return client.name return None
'Ensure the information from the router is up to date. Return boolean if scanning successful.'
def _update_info(self):
data = self._get_data() if (not data): return False active_clients = [client for client in data if client.state] self.last_results = active_clients _LOGGER.debug(('Active clients: ' + '\n'.join((((client.mac + ' ') + client.name) for client in active_clients)))) return True
'Get the devices\' data from the router. Returns a list with all the devices known to the router DHCP server.'
def _get_data(self):
array_regex_res = self.ARRAY_REGEX.search(self._get_devices_response()) devices = [] if array_regex_res: device_regex_res = self.DEVICE_REGEX.findall(array_regex_res.group(1)) for device in device_regex_res: device_attrs_regex_res = self.DEVICE_ATTR_REGEX.search(device) ...
'Get the raw string with the devices from the router.'
def _get_devices_response(self):
cnt = requests.post('http://{}/asp/GetRandCount.asp'.format(self.host)) cnt_str = str(cnt.content, cnt.apparent_encoding, errors='replace') _LOGGER.debug('Loggin in') cookie = requests.post('http://{}/login.cgi'.format(self.host), data=[('UserName', self.username), ('PassWord', self.password), ('x.X_...
'Initialize the scanner.'
def __init__(self, config):
self.host = config[CONF_HOST] self.last_results = {} response = self._make_request() if (not (response.status_code == 200)): raise ConnectionError('Cannot connect to Linksys Access Point')
'Scan for new devices and return a list with device IDs (MACs).'
def scan_devices(self):
self._update_info() return self.last_results.keys()
'Return the name (if known) of the device.'
def get_device_name(self, mac):
return self.last_results.get(mac)
'Check for connected devices.'
def _update_info(self):
_LOGGER.info('Checking Linksys Smart Wifi') self.last_results = {} response = self._make_request() if (response.status_code != 200): _LOGGER.error('Got HTTP status code %d when getting device list', response.status_code) return False try: data...
'Initialize the scanner.'
def __init__(self, config):
self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = config[CONF_PASSWORD] self.last_results = {} data = self.get_thomson_data() self.success_init = (data is not None)
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return [client['mac'] for client in self.last_results]
'Return the name of the given device or None if we don\'t know.'
def get_device_name(self, device):
if (not self.last_results): return None for client in self.last_results: if (client['mac'] == device): return client['host'] return None
'Ensure the information from the THOMSON router is up to date. Return boolean if scanning successful.'
def _update_info(self):
if (not self.success_init): return False _LOGGER.info('Checking ARP') data = self.get_thomson_data() if (not data): return False active_clients = [client for client in data.values() if (client['status'].find('C') != (-1))] self.last_results = active_clients return True
'Retrieve data from THOMSON and return parsed result.'
def get_thomson_data(self):
try: telnet = telnetlib.Telnet(self.host) telnet.read_until('Username : ') telnet.write((self.username + '\r\n').encode('ascii')) telnet.read_until('Password : ') telnet.write((self.password + '\r\n').encode('ascii')) telnet.read_until('=>') telnet...
'Initialize the scanner.'
def __init__(self, config):
host = config[CONF_HOST] (username, password) = (config[CONF_USERNAME], config[CONF_PASSWORD]) self.parse_macs = re.compile(('[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-' + '[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}')) self.host = host self.username = username self.password = password self.last_results =...
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return self.last_results
'Get firmware doesn\'t save the name of the wireless device.'
def get_device_name(self, device):
return None
'Ensure the information from the TP-Link router is up to date. Return boolean if scanning successful.'
def _update_info(self):
_LOGGER.info('Loading wireless clients...') url = 'http://{}/userRpm/WlanStationRpm.htm'.format(self.host) referer = 'http://{}'.format(self.host) page = requests.get(url, auth=(self.username, self.password), headers={'referer': referer}, timeout=4) result = self.parse_macs.findall(page.text) ...
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return self.last_results.keys()
'Get firmware doesn\'t save the name of the wireless device.'
def get_device_name(self, device):
return self.last_results.get(device)
'Ensure the information from the TP-Link router is up to date. Return boolean if scanning successful.'
def _update_info(self):
_LOGGER.info('Loading wireless clients...') url = 'http://{}/data/map_access_wireless_client_grid.json'.format(self.host) referer = 'http://{}'.format(self.host) username_password = '{}:{}'.format(self.username, self.password) b64_encoded_username_password = base64.b64encode(username_password....
'Initialize the scanner.'
def __init__(self, config):
self.stok = '' self.sysauth = '' super(Tplink3DeviceScanner, self).__init__(config)
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() self._log_out() return self.last_results.keys()
'Get the firmware doesn\'t save the name of the wireless device. We are forced to use the MAC address as name here.'
def get_device_name(self, device):
return self.last_results.get(device)
'Retrieve auth tokens from the router.'
def _get_auth_tokens(self):
_LOGGER.info('Retrieving auth tokens...') url = 'http://{}/cgi-bin/luci/;stok=/login?form=login'.format(self.host) referer = 'http://{}/webpages/login.html'.format(self.host) response = requests.post(url, params={'operation': 'login', 'username': self.username, 'password': self.password}, headers=...
'Ensure the information from the TP-Link router is up to date. Return boolean if scanning successful.'
def _update_info(self):
if ((self.stok == '') or (self.sysauth == '')): self._get_auth_tokens() _LOGGER.info('Loading wireless clients...') url = 'http://{}/cgi-bin/luci/;stok={}/admin/wireless?form=statistics'.format(self.host, self.stok) referer = 'http://{}/webpages/index.html'.format(self.host) response =...
'Initialize the scanner.'
def __init__(self, config):
self.credentials = '' self.token = '' super(Tplink4DeviceScanner, self).__init__(config)
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return self.last_results
'Get the name of the wireless device.'
def get_device_name(self, device):
return None
'Retrieve auth tokens from the router.'
def _get_auth_tokens(self):
_LOGGER.info('Retrieving auth tokens...') url = 'http://{}/userRpm/LoginRpm.htm?Save=Save'.format(self.host) password = hashlib.md5(self.password.encode('utf')[:15]).hexdigest() credentials = '{}:{}'.format(self.username, password).encode('utf') self.credentials = base64.b64encode(credentials)...
'Ensure the information from the TP-Link router is up to date. Return boolean if scanning successful.'
def _update_info(self):
if ((self.credentials == '') or (self.token == '')): self._get_auth_tokens() _LOGGER.info('Loading wireless clients...') mac_results = [] for clients_url in ('WlanStationRpm.htm', 'WlanStationRpm_5g.htm'): url = 'http://{}/{}/userRpm/{}'.format(self.host, self.token, clients_url) ...
'Scan for new devices and return a list with found MAC IDs.'
def scan_devices(self):
self._update_info() return self.last_results.keys()
'Get firmware doesn\'t save the name of the wireless device.'
def get_device_name(self, device):
return None
'Ensure the information from the TP-Link AP is up to date. Return boolean if scanning successful.'
def _update_info(self):
_LOGGER.info('Loading wireless clients...') base_url = 'http://{}'.format(self.host) header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:53.0) Gecko/20100101 Firefox/53.0', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Lan...
'Initialize the scanner.'
def __init__(self, config):
self.host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = config[CONF_PASSWORD] self.last_results = {} self.token = _get_token(self.host, self.username, self.password) self.mac2name = None self.success_init = (self.token is not None)
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return self.last_results
'Return the name of the given device or None if we don\'t know.'
def get_device_name(self, device):
if (self.mac2name is None): result = self._retrieve_list_with_retry() if result: hosts = [x for x in result if (('mac' in x) and ('name' in x))] mac2name_list = [(x['mac'].upper(), x['name']) for x in hosts] self.mac2name = dict(mac2name_list) else: ...
'Ensure the informations from the router are up to date. Returns true if scanning successful.'
def _update_info(self):
if (not self.success_init): return False result = self._retrieve_list_with_retry() if result: self._store_result(result) return True return False
'Retrieve the device list with a retry if token is invalid. Return the list if successful.'
def _retrieve_list_with_retry(self):
_LOGGER.info('Refreshing device list') result = _retrieve_list(self.host, self.token) if result: return result _LOGGER.info('Refreshing token and retrying device list refresh') self.token = _get_token(self.host, self.username, self.password) return _retrieve_list(...
'Extract and store the device list in self.last_results.'
def _store_result(self, result):
self.last_results = [] for device_entry in result: if (int(device_entry['online']) == 1): self.last_results.append(device_entry['mac'])
'Initialize the scanner.'
def __init__(self, config):
self.last_results = [] self.hosts = config[CONF_HOSTS] self.exclude = config[CONF_EXCLUDE] minutes = config[CONF_HOME_INTERVAL] self._options = config[CONF_OPTIONS] self.home_interval = timedelta(minutes=minutes) self.success_init = self._update_info() _LOGGER.info('Scanner initialize...
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return [device.mac for device in self.last_results]
'Return the name of the given device or None if we don\'t know.'
def get_device_name(self, mac):
filter_named = [device.name for device in self.last_results if (device.mac == mac)] if filter_named: return filter_named[0] return None
'Scan the network for devices. Returns boolean if scanning successful.'
def _update_info(self):
_LOGGER.info('Scanning...') from nmap import PortScanner, PortScannerError scanner = PortScanner() options = self._options if self.home_interval: boundary = (dt_util.now() - self.home_interval) last_results = [device for device in self.last_results if (device.last_update > boundary)]...
'Initialize the scanner.'
def __init__(self, config):
host = config[CONF_HOST] self.username = config[CONF_USERNAME] self.password = config[CONF_PASSWORD] self.parse_api_pattern = re.compile('(?P<param>\\w*) = (?P<value>.*);') self.last_results = {} self.url = 'http://{}/ubus'.format(host) self.session_id = _get_session_id(self.url, self....
'Scan for new devices and return a list with found device IDs.'
def scan_devices(self):
self._update_info() return self.last_results
'Return the name of the given device or None if we don\'t know.'
@_refresh_on_acccess_denied def get_device_name(self, mac):
if (self.leasefile is None): result = _req_json_rpc(self.url, self.session_id, 'call', 'uci', 'get', config='dhcp', type='dnsmasq') if result: values = result['values'].values() self.leasefile = next(iter(values))['leasefile'] else: return if (self.mac...
'Ensure the information from the Luci router is up to date. Returns boolean if scanning successful.'
@_refresh_on_acccess_denied def _update_info(self):
if (not self.success_init): return False _LOGGER.info('Checking ARP') if (not self.hostapd): hostapd = _req_json_rpc(self.url, self.session_id, 'list', 'hostapd.*', '') self.hostapd.extend(hostapd.keys()) self.last_results = [] results = 0 for hostapd in self.hostapd: ...
'Initialize the sensor.'
def __init__(self, weather_data, name, unit):
self._name = name self._data = weather_data self._unit = unit
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the current condition.'
@property def condition(self):
try: return self.hass.data[DATA_CONDITION][int(self._data.yahoo.Now['code'])] except (ValueError, IndexError): return STATE_UNKNOWN
'Return the temperature.'
@property def temperature(self):
return self._data.yahoo.Now['temp']
'Return the unit of measurement.'
@property def temperature_unit(self):
return self._unit
'Return the pressure.'
@property def pressure(self):
return self._data.yahoo.Atmosphere['pressure']
'Return the humidity.'
@property def humidity(self):
return self._data.yahoo.Atmosphere['humidity']
'Return the visibility.'
@property def visibility(self):
return self._data.yahoo.Atmosphere['visibility']
'Return the wind speed.'
@property def wind_speed(self):
return self._data.yahoo.Wind['speed']
'Return the wind direction.'
@property def wind_bearing(self):
return self._data.yahoo.Wind['direction']