Giter Site home page Giter Site logo

pynetgear's Introduction

pyNetgear

pipeline status

pyNetgear provides an easy to use Python API to control your Netgear router. It uses the SOAP-api on modern Netgear routers to communicate. It is built by reverse engineering the requests made by the NETGEAR Genie app.

pyNetgear works with Python 2 and 3.

If you are connected to the network of the Netgear router, a host is optional. If you are connected via a wired connection to the Netgear router, a password is optional. The username defaults to admin. The port defaults to 5000. The ssl defaults to false. You can specify url and it will take precedence on host/port/ssl parameters. This allows the use of HTTPS, https://orbilogin.com for example.

It currently supports the following operations:

login
Logs in to the router. Will return True or False to indicate success.

get_attached_devices
Returns a list of named tuples describing the device signal, ip, name, mac, type, link_rate and allow_or_block.

get_attached_devices_2
Returns a list of named tuples describing the device signal, ip, name, mac, type, link_rate, allow_or_block, device_type, device_model, ssid and conn_ap_mac.

This call is slower and probably heavier on the router load.

get_traffic_meter
Return a dict containing the traffic meter information from the router (if enabled in the webinterface).

allow_block_device
Allows user to block/unblock devices from accessing router by specifying mac_addr and new device_status (Block/Allow) Note: In order to use this function, Remote Management must be enabled in the router's admin settings.

Installation

You can install PyNetgear from PyPi using pip3 install pynetgear (use pip if you're still using Python 2).

Usage

To test run from the console: $ python -m pynetgear [<pass>] [<host>] [<user>] [<port>] [<ssl>]

To use within your Python scripts:

from pynetgear import Netgear

netgear = Netgear(password=mypassword)

for i in netgear.get_attached_devices():
    print i

Supported routers

It has been tested with the Netgear R6300 router and the Netgear WNDR4500 router. According to the NETGEAR Genie app description, the following routers should work:

  • Netgear Orbi
  • Netgear R7800
  • Netgear R7500v2 (Port 80)
  • Netgear R7000
  • Netgear R6900
  • Netgear R6300
  • Netgear R6250
  • Netgear R6200
  • Netgear R6100
  • Netgear N300 - Model: C3000 (Port 80)
  • Netgear Centria (WNDR4700, WND4720)
  • Netgear WNDR4500
  • Netgear WNDR4300
  • Netgear WNDR4000
  • Netgear WNDR3800
  • Netgear WNDR3700v3
  • Netgear WNDR3700v2
  • Netgear WNDR3400v2
  • Netgear WNR3500Lv2
  • Netgear WNR2200
  • Netgear WNR2000v3
  • Netgear WNR2000v4 (Port 80)
  • Netgear WNR1500
  • Netgear WNR1000v2
  • Netgear WNR1000v3
  • Netgear WNDRMAC
  • Netgear WNR612v2

pynetgear's People

Contributors

arnecl avatar balloob avatar bergautomations avatar caffeinatedmike avatar digdugg avatar etsinko avatar innateessence avatar jurgen-kluft avatar liaden avatar markruys avatar matmaul avatar mrbitbucket avatar nicosingh avatar quentame avatar starkillerog avatar uninen avatar will-cowen avatar yorickvp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pynetgear's Issues

Unexpected entries...

16-01-12 04:48:52 pynetgear: Unexpected entry: []
16-01-12 04:49:02 pynetgear: Unexpected entry: []
16-01-12 04:49:04 pynetgear: Unexpected entry: []
16-01-12 04:49:14 pynetgear: Unexpected entry: []
16-01-12 04:49:19 pynetgear: Unexpected entry: []
16-01-12 04:49:26 pynetgear: Unexpected entry: []
16-01-12 04:49:28 pynetgear: Unexpected entry: []
16-01-12 04:49:38 pynetgear: Unexpected entry: []
16-01-12 04:49:43 pynetgear: Unexpected entry: []

Getting these in home-assistant.log when using the latest version here. Not sure if this is on the home-assistant side or pynetgear, so opening issue here.

Session Error: after 1 hour failure to track devices in Home Assistant

Using pynetgear 0.5.1 to track devices in home assistant 0.84.2 will work on fresh boot for 58 minutes, then result in repeated failures to authenticate and list devices. Polling against Netgear Nighthawk AC2400 with latest firmware (1.2.0.32_1.0.1).

Ref: home-assistant/core#18444

This is a problem with session handling, and can be driven like so:

import pynetgear
import logging
import time

_LOGGER = logging.getLogger()
_LOGGER.setLevel(logging.DEBUG)

iterations = 0
# should fail after 58 minutes worth of loops so watch out
sleeptime = 60
# one request per minute until failure, just so we can see something happening as we check back

error_condition = False

ng = pynetgear.Netgear('password', '192.168.1.1', 'admin', 5000)
while not error_condition:
    iterations += 1
    logging.info("attempt: %s"%iterations)
    try: 
        results = ng.get_attached_devices()
        logging.info("found devices: %s"%len(results))
        time.sleep(sleeptime)
    except:
        error_condition = True
        logging.error("FAILURE DETECTED")

Error with Netgear R9000

Hey there!

Just wanted to let you know, that the python script doesn't seem to work with an R9000 Nighthawk x10.
The router runs on the newest firmware: V1.0.4.2

This is the error log from home assistant:

2018-06-26 11:48:57 INFO (SyncWorker_13) [pynetgear] Get attached devices
2018-06-26 11:48:57 INFO (SyncWorker_13) [pynetgear] Login
2018-06-26 11:48:57 ERROR (SyncWorker_13) [pynetgear] Error talking to API

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 83, in create_connection
raise err
File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 73, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
self, "Failed to establish a new connection: %s" % e)

urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x148d3e4fd9b0>: Failed to establish a new connection: [Errno 111] Connection refused


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.2.1', port=5000): Max retries exceeded with url: /soap/server_sa/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x148d3e4fd9b0>: Failed to establish a new connection: [Errno 111] Connection refused',))


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pynetgear/__init__.py", line 236, in _make_request
data=message, timeout=10, verify=False)
File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.2.1', port=5000): Max retries exceeded with url: /soap/server_sa/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x148d3e4fd9b0>: Failed to establish a new connection: [Errno 111] Connection refused',))

2018-06-26 11:48:57 ERROR (SyncWorker_13) [homeassistant.components.device_tracker.netgear] Failed to Login

2018-06-26 11:48:57 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform netgear

Greetings!

DFS selection

Hi guys,

Do yo plan to include a feature for DFS channel selection. Basically looking at making methods to change the DFS channel. I have an R7800 and although I could select DFS channel from the UI, when the router detects a Radar it automatically falls back to a non-DFS channel. But, I would like to have it search for another DFS channel that's available and use it isntead. If all DFS channels are in use, the router should obviously fall back to using Non-DFS channel.

Errors when testing on R7800 with XR 500 firmware

Hi,

I was trying out the Netgear-function in Home Assistant and I am running in some trouble.
I'm using the Netgear R7800 with a modified firmware meant for the X R 5 0 0 .
When running the pynetgear script manually, this is shown:

{'NewMonthConnectionTime': datetime.timedelta(0, 60), 'NewYesterdayDownload': 0.0, 'NewTodayConnectionTime': datetime.timedelta(0, 60), 'NewLastMonthUpload': (0.0, 0.0), 'NewTodayUpload': 0.0, 'NewWeekDownload': (0.0, 0.0), 'NewMonthUpload': (0.0, 0.0), 'NewWeekConnectionTime': datetime.timedelta(0, 60), 'NewLastMonthDownload': (0.0, 0.0), 'NewYesterdayUpload': 0.0, 'NewLastMonthConnectionTime': datetime.timedelta(0, 120), 'NewMonthDownload': (0.0, 0.0), 'NewYesterdayConnectionTime': datetime.timedelta(0), 'NewTodayDownload': 0.0, 'NewWeekUpload': (0.0, 0.0)}
--- Logging error ---
Traceback (most recent call last):
File "/usr/lib/python3.5/logging/init.py", line 981, in emit
msg = self.format(record)
File "/usr/lib/python3.5/logging/init.py", line 831, in format
return fmt.format(record)
File "/usr/lib/python3.5/logging/init.py", line 568, in format
record.message = record.getMessage()
File "/usr/lib/python3.5/logging/init.py", line 331, in getMessage
msg = msg % self.args
TypeError: %d format: a number is required, not NoneType
Call stack:
File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/srv/homeassistant/lib/python3.5/site-packages/pynetgear/main.py", line 22, in
main()
File "/srv/homeassistant/lib/python3.5/site-packages/pynetgear/main.py", line 12, in main
devices = netgear.get_attached_devices()
File "/srv/homeassistant/lib/python3.5/site-packages/pynetgear/init.py", line 105, in get_attached_devices
be: %d but is: %d""", entry_count, len(entries))
Message: 'Number of devices should be: %d but is: %d'
Arguments: (None, 10)
Device(signal=100, ip='192.168.1.137', name='BOUWE-PC', mac='XX', type='wired', link_rate=None, allow_or_block='Allow', device_type=None, device_model=None, ssid=None, conn_ap_mac=None)
Device(signal=100, ip='192.168.1.109', name='SOLAR-B84B', mac='XX', type='wireless', link_rate=None, allow_or_block='Allow', device_type=None, device_model=None, ssid=None, conn_ap_mac=None)
Device(signal=100, ip='192.168.1.100', name='unnamed device', mac='XX', type='wireless', link_rate=None, allow_or_block='Allow', device_type=None, device_model=None, ssid=None, conn_ap_mac=None)
Device(signal=100, ip='192.168.1.101', name='ANDROID-5728CB9FED8984F9', mac='XX', type='wireless', link_rate=5, allow_or_block='Allow', device_type=None, device_model=None, ssid=None, conn_ap_mac=None)

And several more devices are shown.

Do you have any idea why the error happens? Any fix possible?

Kind regards, bouwew

Version 0.4.0 breaks compatability with WNDR4500

Hello

I'm using pynetgear via home assistant, and a recent upgrade has resulted in a upgrade from pynetgear 0.3.3 to 0.4.0. This does not work on my WNDR4500.

$ pip3 install pynetgear=0.3.3
python3 -m pynetgear pass host user 
# works fine

$ pip3 install pynetgear=0.4.0
python3 -m pynetgear pass host user 
# Error parsing xml response: <?xml version="1.0" encoding="UTF-8"?>

I believe this is a bug.

Also see home-assistant/core#14752

Error parsing xml response

I'm not sure what I'm doing wrong, but my router is a Netgear R6200. I'm attempting to use this package with Home Assistant, but ran into an issue and ran it manually to try to debug more. The XML looks fine to me and even has the list of devices though I removed them. My logs look similar to the capture folder files too.

@MatMaul Have you seen this before by chance?

python -m pynetgear XXXXXX 192.168.1.1 admin   
Error parsing xml response: <?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope
        xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
        soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        >
<soap-env:Body>
    <m:GetTrafficMeterStatisticsResponse
        xmlns:m="urn:NETGEAT-ROUTER:service:DeviceConfig:1">
        <NewTodayConnectionTime>--:--</NewTodayConnectionTime>
        <NewTodayUpload>2.00</NewTodayUpload>
        <NewTodayDownload>3.95</NewTodayDownload>
        <NewYesterdayConnectionTime>--:--</NewYesterdayConnectionTime>
        <NewYesterdayUpload>0.00</NewYesterdayUpload>
        <NewYesterdayDownload>0.00</NewYesterdayDownload>
        <NewWeekConnectionTime>--:--</NewWeekConnectionTime>
        <NewWeekUpload>2.00/0.29</NewWeekUpload>
        <NewWeekDownload>3.95/0.56</NewWeekDownload>
        <NewMonthConnectionTime>--:--</NewMonthConnectionTime>
        <NewMonthUpload>2.00/0.07</NewMonthUpload>
        <NewMonthDownload>3.95/0.13</NewMonthDownload>
        <NewLastMonthConnectionTime>--:--</NewLastMonthConnectionTime>
        <NewLastMonthUpload>0.00/0.00</NewLastMonthUpload>
        <NewLastMonthDownload>0.00/0.00</NewLastMonthDownload>
    </m:GetTrafficMeterStatisticsResponse>
    <ResponseCode>000</ResponseCode>
</soap-env:Body>
</soap-env:Envelope>

None
Error parsing xml response: <?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope
        xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
        soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        >
<soap-env:Body>
    <m:GetAttachDeviceResponse
        xmlns:m="urn:NETGEAT-ROUTER:service:DeviceInfo:1">
        <NewAttachDevice>XXXXXXXXXXXX</NewAttachDevice>
    </m:GetAttachDeviceResponse>
    <ResponseCode>000</ResponseCode>
</soap-env:Body>
</soap-env:Envelope>

Error communicating with the Netgear router

Update PyPi version with get_traffic_meter capability

Is it too early to request that the Python Package Index (PyPi) be updated with a version of pyNetgear that includes get_traffic_meter functionality? I've got a Netgear R8000 running the latest firmware and its traffic meter web UI is presenting data that is occasionally very obviously wrong (eg. monthly traffic temporarily decreasing instead of increasing). I'd like to see if pyNetgear extracts the same bad data with SOAP and perhaps figure out what's going wrong. I'm brand new to Python and have no familiarity with Git.

Add support for Nighthawk X4 R7500v2

Hi,
I found that this router sends 8 items in the get_attached_devices. I added the case where an array count of 8 is treated similar to the first case (7).

I updated the code and submitted a PR.

#24

Thanks!

John

Feature request: Add operation to retrieve firewall logs

This request is to add functionality to retrieve firewall logs as shown under Administration > Logs in the Netgear GUI. I was able to test to a call to API GetSystemLogs (referenced from #20 (comment)) on an R8000 (V1.0.4.76_10.1.82), but the response returns an incomplete subset of the logs (always returns 22 vs. 200+ lines shown in the GUI). Also, the last line gets truncated and the logs in the response do not seem to get refreshed as frequent as when viewing them in the GUI.

def get_logs(self):
        success, response = self._make_request(
            SERVICE_DEVICE_INFO,
            "GetSystemLogs"
        )

        if not success:
            return None

        success, node = _find_node(
            response.text,
            ".//GetSystemLogsResponse/NewLogDetails")
        if not success:
            return None

        logs = node.text.split('\n')
        
        return logs

Example response snippet showing the truncated ending line.

[Admin login] from source 192.168.2.66, Thursday, Dec 30,2021 12:11:43
[Site allowed: firetvcaptiveportal.com] from source 192.168.2.52, Thursday, Dec 30,2021 12:11:18
[Site allowed: clientconfig.akamai.steamstatic.com] from source 192

get_attached_devices fails due to & in device name

I have an AT&T device that registers with the & in the name. This causes get_attached_devices to fail with the error:
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 9, column 407

If I remove this device from the network, then get_attached_devices returns just fine. The actual device name is "AT&T TV - C71LB8CR111646"

Getting Invalid Response

I'm using pynetgear in a hass.io rpi system to monitor presence by probing the device list on my Netgear Nighthawk X10 R9000 (hitting it about every 30 seconds with a query). The system works about 80% of the time and I'm able to get the list of devices without issue but for 10% of the time (and it seems random/sporadic) I get the following error:

2019-05-28 20:41:06 ERROR (SyncWorker_1) [pynetgear] Invalid response
2019-05-28 20:41:06 DEBUG (SyncWorker_1) [pynetgear] 200
{'Content-Length': '1518', 'Content-Type': 'text/xml; charset="UTF-8"', 'Server': 'Linux/2.6.15 uhttpd/1.0.0 soap/1.0'}
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:GetAttachDeviceResponse xmlns:m="urn:NETGEAR-ROUTER:service:DeviceInfo:1">    
    <NewAttachDevice><!-- snipped for privacy --></NewAttachDevice>
</m:GetAttachDeviceResponse>
<ResponseCode>000</ResponseCo</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

2019-05-28 20:41:06 ERROR (SyncWorker_1) [pynetgear] Get attached devices failed

Clearly the XML that is printed out in the debug log is invalid:

<ResponseCode>000</ResponseCo</SOAP-ENV:Body>

At first I thought it might be random dropped packets losing the response... but it is consistent in not printing the full tag. Sometimes it breaks at different spots where it only prints </Respon but it is always this closing tag that is printed.

The question is... is this actually coming from the netgear... or is this some sort of preprocessing of the response that corrupts it within pynetgear?

Either way, I see you don't actually validate the XML any way around this?

Router webui not accessible after using pynetgear

Version: 0.5.2
Router: Netgear R8000
Use case: homeassistant 0.89.2 device tracker

When I configured my device tracker and booted up homeassistant, I can no longer access the router's web ui via direct IP or routerlogin.net but accessing the device via pynetgear works just fine

I can ping the device just fine, but accessing the web ui fails with a connection refused message. Stopping homeassistant doesn't resolve the issue either. Rebooting the router allows me to access the web ui again at least until I turn homeassistant back on

Need help to retrieve traffic meter details for WNDR3700v3

I have enabled traffic metering in the webUI
image

Following is the code that I am using based on the sample provided

from pynetgear import Netgear
netgear = Netgear(password="xx")
print("Traffic meter details -->>")
traffic = netgear.get_traffic_meter()
print(traffic)

I am using Python 3.7.4
Following is the output I get

$ python3 net.py
Traffic meter details -->>
Invalid response
Invalid response
None

The same code when executed in Python3 version Python 3.7.3
I get the following output

$ python3 traffic.py 
Traffic meter details -->>
Error finding node in XML response
None

Looks like I am missing something. Can you please help?

ResponseCode changes in Nighthawks?

I'm using your code on a Nighthawk M1. It looks like Netgear changed the < ResponseCode > from 3 to 4 digits. Otherwise SOAP requests seem to be going through. Still testing.

Also looks like the traffic meter request has changed. GetTrafficMeterStatistics/GetTrafficMeterStatisticsResponse comes back as invalid request.

Improvement: Catch exceptions for timeouts

With version 0.33, pynetgear does not differ between returnCodes or timeouts and e.g. throws an exception (requests.exceptions.ConnectionError) in case the router can't be accessed. See also HA Issue 1988

Expected: A comprehensive log-entry.

Unexpected entry, likely due to space in device name

It looks like there are parse errors related to having spaces in the device name. I think my model (C7000-100NAS) supports the spaces, whereas others don't. The get_attached_devices method is working for me until it encounters the first device with a space in the name ("Roku Premiere"), then no devices are listed beyond that IP. The specific error I'm getting is:

Unexpected entry: ['16', '192.168.0.101', 'Roku Pre']

Let me know if there's more information that would be helpful. Thanks!

Garbage response from R6220

I recently updated my Netgear R6220 to firmware version V1.1.0.50_1.0.1 . After noticing some issues with device detection in Home Assistant, I came here to do some more investigation on the library. So far, I'm stuck with the following error:

Error parsing respone: <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <m:GetAttachDeviceResponse xmlns:m="urn:NETGEAR-ROUTER:service:DeviceInfo:1">
      <NewAttachDevice>16@1;10.111.76.20;UNKNOWN;5C:CF:7F:A7:FF:D2
;NOWN;5C:CF:7F:A7:FF:D2
;;wired;0;100;Block@2;10.111.76.22;UNKNOWN;5C:CF:7F:97:28:B1
;NOWN;5C:CF:7F:97:28:B1
;;wired;0;100;Block@3;10.111.76.28;UNKNOWN;F0:FE:6B:36:7C:68
;NOWN;F0:FE:6B:36:7C:68
;;wired;0;100;Block@4;10.111.76.29;UNKNOWN;A0:20:A6:0C:CE:40
;NOWN;A0:20:A6:0C:CE:40
;;wired;0;100;Block@5;10.111.76.30;UNKNOWN;50:A4:C8:FD:5D:69
;NOWN;50:A4:C8:FD:5D:69
;;wired;0;100;Block@6;10.111.76.31;UNKNOWN;50:C7:BF:53:6B:AE
;NOWN;50:C7:BF:53:6B:AE
;;wired;0;100;Block@7;10.111.76.50;UNKNOWN;AC:37:43:A9:C9:A2
;NOWN;AC:37:43:A9:C9:A2
;;wired;0;100;Block@8;10.111.76.137;GERTHDESKTOP;BC:5F:F4:54:79:A9
;RTHDESKTOP;BC:5F:F4:54:79:A9
;;wired;0;100;Block@9;10.111.76.148;UNKNOWN;00:26:B9:1D:28:0E
;KNOWN;00:26:B9:1D:28:0E
;;wired;0;100;Block@10;10.111.76.29;ESP_0CCE40;A0:20:A6:0C:CE:40;wireless;65;81;Allow@11;10.111.76.28;HF-LPB100-ZJ200;F0:FE:6B:36:7C:68;wireless;65;70;Allow@12;10.111.76.20;SONOFF2-8146;5C:CF:7F:A7:FF:D2;wireless;65;78;Allow@13;10.111.76.31;HS100;50:C7:BF:53:6B:AE;wireless;65;100;Allow@14;10.111.76.30;ANDROID-FBC2783DD21AF18C;50:A4:C8:FD:5D:69;wireless;65;100;Allow@15;10.111.76.22;SONOFF1-2225;5C:CF:7F:97:28:B1;wireless;65;96;Allow@16;10.111.76.50;ANDROID-85756E72DBBE8FE8;AC:37:43:A9:C9:A2;wireless;780;100;Allow</NewAttachDevice>
    </m:GetAttachDeviceResponse>
    <ResponseCode>000</ResponseCode>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Error communicating with the Netgear router

It looks like contents of the tag is corrupted, based on what the code is looking for. I would guess this is a defect in the router firmware, but I'm not certain... Has anyone else seen this or something similar? I unfortunately don't have a "before" capture from the previous firmware on the router.

Different response on Nighthawk R7800 on latest version

Router: Nighthawk R7800
Firmware: V1.0.2.36

After one of the lastest updates the response had changed:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:GetAttachDeviceResponse xmlns:m="urn:NETGEAR-ROUTER:service:DeviceInfo:1">    <NewAttachDevice>
@1;192.168.***.***;HOME-SERVER;18:66:**:**:**:**;wired;;100;Allow@2;192.168.***.***;&lt;unknown&gt;;B0:B9:**:**:**:**;wired;;100;Allow@3;192.168.***.***;HARTIES-WP;48:86:**:**:**:**;wireless;38;52;Allow@4;192.168.***.***;HARTIES-PC;1C:1B:**:**:**:**;wired;;100;Allow@5;192.168.***.***;HUAWEI_P9_LITE;A4:71:**:**:**:**;wireless;56;64;Allow@6;192.168.***.***;KIDS-PI;74:DA:**:**:**:**;wireless;70;62;Allow@7;192.168.***.***;HP08B22A;84:34:**:**:**:**;wireless;56;86;Allow@8;192.168.***.***;*****-HANDY;38:F2:**:**:**:**;wireless;146;68;Allow@9;192.168.***.***;****PI;B8:27:**:**:**:**;wired;;100;Allow@10;192.168.***.***;WINDOWS-PHONE;9C:6C:**:**:**:**;wireless;70;70;Allow@11;192.168.***.***;ANDROID-*****;0C:4E:**:**:**:**;wireless;25;48;Allow@12;192.168.***.***;KELLER_*****_WALL-****;60:01:**:**:**:**;wireless;70;80;Allow@13;192.168.***.***;KELLER_MAIN-****;60:01:**:**:**:**;wireless;70;72;Allow@14;192.168.***.***;SONOFF-****;60:01:**:**:**:**;wireless;70;56;Allow</NewAttachDevice>
</m:GetAttachDeviceResponse>
<ResponseCode>000</ResponseCode>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

To get pynetgear working again with home assistent and my router I needed to add the re.DOTALL param to the regex in get_attached_devices
I also needed to allow parsing if the length is 8 in get_attached_devices
The router also does not send the number of devices anymore.

Timeout under home assistant

I have a D6200 on the latest firmware with 7 wired connections and about 20 wireless. Doesn't sound too onerous, but the NetGenie interface takes over 10 seconds to display. When I enabled it in Home Assistant, I get timeout errors more than once a minute (see below). It seems to find some of the devices but not all. I noticed the source to pynetgear has timeout=10 hardcoded. Could this be my problem, and should I be expecting better? pynetgear is running inside HA, inside Docker, inside VirtualBox on a PC wired to the D6200.

If I run
python3 -m pynetgear <password> 192.168.0.1
I get json output starting with "{'NewTodayConnectionTime':" and ending in "'NewLastMonthDownload': (0.0, 0.0)}", but all the values are zero. The json is then followed with the same timeout that HA gets. Any help would be much appreciated.

Log Details (ERROR)
Sat Jun 02 2018 14:09:38 GMT+1000 (Australian Eastern Standard Time)

Error talking to API
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
six.raise_from(e, None)
File "", line 2, in raise_from
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3.6/site-packages/urllib3/packages/six.py", line 686, in reraise
raise value
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 389, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 309, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='192.168.0.1', port=5000): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/pynetgear/init.py", line 236, in _make_request
data=message, timeout=10, verify=False)
File "/usr/lib/python3.6/site-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python3.6/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 521, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='192.168.0.1', port=5000): Read timed out. (read timeout=10)

Failed to Login > Error setting up platform netgear (More Details Enclosed)

Platform
Old Laptop running fresh install of Linux Mint, running Home Assistant in Docker. Installed HA using these directions, with a few minor detours

  1. Needing to update python3, since Linux Mint natively comes with 3.5.3. Followed this guide to install python 3.6 along side the typical python3 installation of mint as to not disturb any of linux mint's other functionality.
  2. Needing to pip install docker.io, the default docker library for linux mint, instead of the docker mentioned in the gist
  3. Running each command from the gist individually instead of running the script as a whole.

Home Assistant Version
0.79.3

Router Model
Netgear C3000

Problem
Simply put, cannot get Netgear component to work as device_tracker. Fails to login. I've confirmed the credentials are correct. No matter what I try I cannot seem to get the component configured.

Setup Variations I've tried in Configuration.yaml

device_tracker:
  - platform: netgear
    host: 192.168.0.1
    port: 80
    username: admin
    password: REDACTED
device_tracker:
  - platform: netgear
    host: 192.168.0.1
    username: admin
    password: REDACTED
device_tracker:
  - platform: netgear
    password: REDACTED

Full Log

2018-10-04 08:04:46 ERROR (MainThread) [homeassistant.components.device_tracker] Unable to load /config/known_devices.yaml: Config file not found: /config/known_devices.yaml
2018-10-04 08:04:47 ERROR (SyncWorker_3) [pynetgear] Error talking to API
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/local/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.6/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 367, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/local/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.6/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pynetgear/__init__.py", line 247, in _make_request
    data=message, timeout=30, verify=False)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 495, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
2018-10-04 08:04:47 ERROR (SyncWorker_3) [homeassistant.components.device_tracker.netgear] Failed to Login
2018-10-04 08:04:47 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform netgear
018-10-04 12:15:55 WARNING (SyncWorker_0) [netdisco.ssdp] Found malformed XML at http://192.168.0.10:9080: status=ok

Edit
I should also note that the laptop running the HA instance is connected directly to the router via Ethernet cable.
Edit 2
I notice my router isn't included on the Supported Routers List, but I can access & manage the router using the Netgear Genie android app and my device is listed in the acceptable devices in the nodejs version of this program that this was ported over from.

CC: @MatMaul

Large subset of Netgear SOAP API available for enhancements

In issue #17 I was seeking a pyNetgear release to aid me automating the extraction of traffic statistics from my router. Given that release could not happen as quickly as I would have liked, I was inspired to take a closer look at the Netgear SOAP API myself to see what I could do without pyNetgear and using a programming language I actually know (ie. not Python). Since pyNetgear was the inspiration, I would like to return the favour.

Netgear does not publish any information about its SOAP API that I have been able to find, nor are they helpful to those who ask. Their routers are security devices and exposing an important point of access without documentation is really not at all acceptable, especially when that interface has already been the source of at least one serious security vulnerability in 2015.

I provided some preliminary hints in issue #17 about additional methods that exist in the Netgear SOAP API. I have identified a large number of API methods. I have only tested about 75 of those on a Netgear Nighthawk X6 R8000, primarily those methods for which the SOAP request does not require parameters. Deducing request parameters requires an even deeper dive that I will probably leave to others. Network packet sniffing while one of the Netgear GENIE applications is in use is a relatively easy way to learn more about the small subset of API methods it makes use of, but the rest must be figured out by other means.

I have attached a commented log file of actual SOAP request/response pairs that I have tested. I trust it will provide some ideas if enhancing pyNetgear functionality is desired. Perhaps so too for developers of other projects, if they happen to see this, such as @gruijter. It would be great to see someone produce a Netgear module for CPAN too. Share the knowledge gained and open up the Netgear SOAP API. It's a buggy mess and doubtless has more security vulnerabilities, so more eyes are good.

Log file: netgear-r8000-soap.txt

SSL warnings

SSL warnings are showing up on STDERR:

/usr/local/lib/python3.7/site-packages/urllib3-1.24.1-py3.7.egg/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
/usr/local/lib/python3.7/site-packages/urllib3-1.24.1-py3.7.egg/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
/usr/local/lib/python3.7/site-packages/urllib3-1.24.1-py3.7.egg/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

This can be ignored for CLI usage bash scripting, but I think it would be good to either verify the connection or if there is something for us users to do to make this not happen, then improve the documentation.

Error talking to API/Errror communicating with the Netgear router

Router: Netgear C6250 (not on supported list, so that could be the issue)

During initial setup of pynetgear I hit an error immediately after entering credentials, host and port:
Error talking to API
This error is immediately followed by multiple connection reset errors:
ConnectionResetError: [Errno 104] Connection reset by peer
And then a final error is thrown:
Error communicating with the Netgear router

I figure the router model may just not be supported. Is this happening to anyone with routers on the supported list? Has anyone successfully set up pynetgear with a C6250 router?

Netgear r7000

netgear = pynetgear.Netgear('192.168.0.239',5000)
for i in netgear.get_attached_devices():
... print i

And nothing happens , but the wireless is working properly .

CLI usage without password errors

Was attempting to run from one of my SBC's instead of from my laptop on wifi and discovered that there is an error in the passwordless approach (since from the docs we don't need a password for wired connnections).

/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
Invalid response
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/site-packages/pynetgear/__main__.py", line 133, in <module>
    main()
  File "/usr/local/lib/python3.7/site-packages/pynetgear/__main__.py", line 122, in main
    results = run_subcommand(netgear, args)
  File "/usr/local/lib/python3.7/site-packages/pynetgear/__main__.py", line 103, in run_subcommand
    return netgear.get_attached_devices()
  File "/usr/local/lib/python3.7/site-packages/pynetgear/__init__.py", line 136, in get_attached_devices
    "GetAttachDevice")
  File "/usr/local/lib/python3.7/site-packages/pynetgear/__init__.py", line 354, in _make_request
    if not self.login():
  File "/usr/local/lib/python3.7/site-packages/pynetgear/__init__.py", line 93, in login
    return self.login_v2()
  File "/usr/local/lib/python3.7/site-packages/pynetgear/__init__.py", line 101, in login_v2
    None, False)
  File "/usr/local/lib/python3.7/site-packages/pynetgear/__init__.py", line 366, in _make_request
    params += "<" + k + ">" + _map[k] + "</" + k + ">\n"
TypeError: can only concatenate str (not "NoneType") to str

Setting PYNETGEAR_PASSWORD='' doesn't mitigate the problem either; however, it is currently taking None by default: https://github.com/MatMaul/pynetgear/blob/0.6.1/pynetgear/__init__.py#L55

Reboot Router

I was able to get Reboot to work, not very adept at github, so if you want to add to your init.py this works.

def reboot_router(self):
    """
    Reboot Router
    
    """
    _LOGGER.info("Reboot Router")

    success, response = self._make_request(SERVICE_DEVICE_CONFIG,
                                           "Reboot")

    print(response.text)

    if not success:
        _LOGGER.error("Reboot failed")
        return None

    success, node = _find_node(
        response.text,
        ".//Reboot")
    if not success:
        return None

Response -

<soap-env:Envelope
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>
soap-env:Body
<m:RebootResponse
xmlns:m="urn:NETGEAR-ROUTER:service:DeviceConfig:1">
</m:RebootResponse>
000
</soap-env:Body>
</soap-env:Envelope>

Anyone any experience with pynetgear on Orbi AC3000?

Hi,

I have made a nodejs based app for the Homey home automation platform. See https://apps.athom.com/app/com.gruijter.netgear

My code is loosely based on the work from pynetgear. I have made a nodejs module that can be found here: https://github.com/gruijter/netgear.js

I have feedback that it works on R7000, R8000. But on the Orbi AC3000 it fails somehow. Does anyone have experience with the Orbi? E.g. what port is the SOAP interface port on, and does pynetgear work with the orbi? Or are there differences in SOAP commands/responses?

Thx!

Include Upload/Download in list of devices

I hacked the code local to get the Upload/Download attributes out of the device XML. Once Dynamic QOS is turned on these attributes will show the bandwidth used by the device. Here is a sample of the results from one of the devices on my network.

<Device>
<IP>192.168.1.28</IP> 
<Name>Playstation</Name> 
<NameUserSet>true</NameUserSet> 
<MAC>C0:</MAC> 
<ConnectionType>2.4GHz</ConnectionType> 
<SSID>network</SSID> 
<Linkspeed></Linkspeed> 
<SignalStrength>98</SignalStrength> 
<AllowOrBlock>Allow</AllowOrBlock> 
<Schedule>false</Schedule> 
<DeviceType>47</DeviceType> 
<DeviceTypeUserSet>true</DeviceTypeUserSet> 
<Upload>0</Upload> 
<Download>0</Download> 
<QosPriority>4</QosPriority> 
</Device> 

I have an R6900.

Feature request: Show and edit device access

Great work! Would it be possible to add the capability to block network access for a device? Use case would be to block my sons iPad after 10pm, or when he has been using too much traffic by watching youtube ๐Ÿ˜

Too many values to unpack

Running this on a NetGear WNDR3700v3 and receiving the following error after specifying login details and IP address in my configuration.yaml.

16-01-02 02:01:48 homeassistant.components.device_tracker: Error setting up platform netgear
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/device_tracker/__init__.py", line 124, in setup_platform
    scanner = platform.get_scanner(hass, {DOMAIN: p_config})
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/device_tracker/netgear.py", line 36, in get_scanner
    scanner = NetgearDeviceScanner(host, username, password)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/device_tracker/netgear.py", line 59, in __init__
    results = self._api.get_attached_devices()
  File "/home/pi/.homeassistant/lib/pynetgear/__init__.py", line 77, in get_attached_devices
    ip, name, mac, link_type = info[1:5]
ValueError: need more than 3 values to unpack

I took liberty to do a print before the 3 value unpack and received the following output of the contents of info the line before the exception

>>> print(ng.get_attached_devices())
['12@1', '192.168.1.2', '--', '28:C6:8E:CE:9C:AB']

Not sure what the data should be to make a working patch here. Let me know if I can help debug further.

Pynetgear not compatible with new Nighthawk based interfaces vs Genie

Valid Pynetgear configuration returns "Failed to login, Invalid response, Unauthorized response, let's login and retry..." based off of what I understand or I guess don't understand, I am assuming the pynetgear addon isn't compatible with new netgear devices yet (Nighthawk MK63) if there is anything I can do to help please let me know, but my technical knowledge is limited.

My Config as follows
#Netgear Router
device_tracker:

  • platform: netgear
    host: 192.168.1.1
    port: 80
    username: !secret Net_User
    password: !secret Net_Pass
    accesspoints:
    • xx:xx:xx:xx:xx:xx
    • xx:xx:xx:xx:xx:xx

dashes are replaced by bullets, I don't know how to properly format it

How to Set?

Does anyone know how to set parameters, and not just read them?

pynetgear stopped working for WNR3500Lv2 router

I recently noticed that my Home Assistant started showing me 'Error parsing xml response' error during start up of pynetgear. I did some digging and here what I found:
In commit b8c7ce4 a new parsing mechanism for response was introduced - now it is always parsed as XML.

Unfortunately my router returns an XML with a typo in it. Pynetgear expects the node GetAttachDeviceResponse to have the urn:NETGEAR-ROUTER:service:DeviceInfo:1 namespace while my router returns it as urn:NETGEAT-ROUTER:service:DeviceInfo:1. I updated my router to the latest firmware (V1.2.0.50_50.0.90) and it didn't solve the problem.

I'm not sure what the best solution for this problem could be. Do you think ditching namespaces altogether might fix this issue?

Not getting correct data from get_traffic_meter()

traffic meter is enabled and shows:
image

I see that upload avg in the picture uses a . for the decimals, where the other values ues a ,
(can there be some error in the conversion?)

but the output I get is missing a lot of detail:
{
'NewTodayConnectionTime': datetime.timedelta(seconds = 56100),
'NewTodayUpload': 603.62,
'NewTodayDownload': None,
'NewYesterdayConnectionTime': datetime.timedelta(days = 1),
'NewYesterdayUpload': None,
'NewYesterdayDownload': None,
'NewWeekConnectionTime': datetime.timedelta(days = 3, seconds = 56100),
'NewWeekUpload': None,
'NewWeekDownload': None,
'NewMonthConnectionTime': datetime.timedelta(days = 3, seconds = 56100),
'NewMonthUpload': None,
'NewMonthDownload': None,
'NewLastMonthConnectionTime': datetime.timedelta(days = 30, seconds = 85260),
'NewLastMonthUpload': None,
'NewLastMonthDownload': None
}

using this code
from pynetgear import Netgear
import numpy as np

netgear = Netgear(password="", host="", user="*", ssl=False,port=80)

x=netgear.get_traffic_meter()
print(x)

Unable to parse Netgear response with non-printable ASCII character: xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 6, column 245

This issue is related to home-assistant/core#15768 and #42.

After much investigation follow from the original issue reported by me and others in homeassistant and #42 version 0.78.3/0.79.0 of homeassistant that uses pynetgear 0.4.1 still have similar issue.

I have investigated further and the root cause of the issue seem to be dealing with non-printable ASCII character.

Specifically, if netgear router was unable to figure out the device name, in their xml response, it will contain some ^P character (data link character). Copy and paste from the terminal will not reveal the character, which explain why the previous issue reported cannot be reproduced. This character can only be revealed when printing the response straight to a file.

I have attached a sample response (with ^P (or DLE character)) for example.

Is it possible to filter out non-printable characters?

Here is a snippet of code that I temporarily implemented for work-around:

Under pynetgear/__init__.py

import string
def _find_node(response, xpath):

    response = ''.join(filter(lambda x: x in string.printable, response)) # This is the line that I added (with import above)
    it = ET.iterparse(StringIO(response))
    # strip all namespaces
    for _, el in it:
        if '}' in el.tag:
            el.tag = el.tag.split('}', 1)[1]
    node = it.root.find(xpath)
    if node is None:
        _LOGGER.error("Error finding node in response: %s", response)
        return False, None

    return True, node

sample.txt

[pynetgear] Can't parse attached devices string

Hi again.

On hassbian 84.3:
Running either 0.5.1, v1-default or master (with latest commit a7a6974) I still have the same errors as before:
2018-12-19 04:51:53 ERROR (Thread-7) [pynetgear] Can't parse attached devices string 2018-12-19 04:59:53 ERROR (Thread-9) [pynetgear] Can't parse attached devices string 2018-12-19 05:02:33 ERROR (Thread-2) [pynetgear] Can't parse attached devices string 2018-12-19 05:06:33 ERROR (Thread-5) [pynetgear] Can't parse attached devices string 2018-12-19 05:13:13 ERROR (Thread-20) [pynetgear] Can't parse attached devices string 2018-12-19 05:39:52 ERROR (Thread-7) [pynetgear] Can't parse attached devices string 2018-12-19 08:07:15 ERROR (Thread-6) [pynetgear] Can't parse attached devices string 2018-12-19 08:33:39 ERROR (Thread-14) [pynetgear] Can't parse attached devices string 2018-12-19 08:50:42 ERROR (Thread-4) [pynetgear] Can't parse attached devices string 2018-12-19 08:52:18 ERROR (Thread-5) [pynetgear] Can't parse attached devices string 2018-12-19 09:34:41 ERROR (Thread-5) [pynetgear] Can't parse attached devices string 2018-12-19 11:25:03 ERROR (Thread-7) [pynetgear] Can't parse attached devices string 2018-12-19 12:02:07 ERROR (Thread-5) [pynetgear] Can't parse attached devices #string

Help for netgear wndr 3700 v5

Hi,
I am a beginner, I tried to use pynetgear but l have an error. Someone , can help me ?
Thank's

pi@raspberrypi:~/pynetgear $ python -m pynetgear pass, 10.0.0.1, user, 5000
No handlers could be found for logger "pynetgear"
Error communicating with the Netgear router

command line throws requests.exceptions.MissingSchema

using a python code file to login or to get traffic meter works without throwing an error, using the same on the command line however throws requests.exceptions.MissingSchema

this works: (with correct values for password, etc)

from pynetgear import Netgear

netgear = Netgear(password="*****", host="******", user="******", ssl=False,port=80)

x=netgear.get_traffic_meter()

this not:

python -m pynetgear --user '' --port '80' --password '' --url "*****" --no-ssl traffic_meter
Error talking to API
Traceback (most recent call last):
File "C:\src\jerry\pynetgear\pynetgear_init_.py", line 480, in make_request
response = requests.post(self.soap_url, headers=headers,
File "C:\Python38\lib\site-packages\requests\api.py", line 119, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python38\lib\site-packages\requests\sessions.py", line 516, in request
prep = self.prepare_request(req)
File "C:\Python38\lib\site-packages\requests\sessions.py", line 449, in prepare_request
p.prepare(
File "C:\Python38\lib\site-packages\requests\models.py", line 314, in prepare
self.prepare_url(url, params)
File "C:\Python38\lib\site-packages\requests\models.py", line 388, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '10.0.0.1/soap/server_sa/': No schema supplied. Perhaps you meant http://10.0.0.1/soap/server_sa/?
Error talking to API
Traceback (most recent call last):
File "C:\src\jerry\pynetgear\pynetgear_init
.py", line 480, in _make_request
response = requests.post(self.soap_url, headers=headers,
File "C:\Python38\lib\site-packages\requests\api.py", line 119, in post
return request('post', url, data=data, json=json, kwargs)
File "C:\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, kwargs)
File "C:\Python38\lib\site-packages\requests\sessions.py", line 516, in request
prep = self.prepare_request(req)
File "C:\Python38\lib\site-packages\requests\sessions.py", line 449, in prepare_request
p.prepare(
File "C:\Python38\lib\site-packages\requests\models.py", line 314, in prepare
self.prepare_url(url, params)
File "C:\Python38\lib\site-packages\requests\models.py", line 388, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '10.0.0.1/soap/server_sa/': No schema supplied. Perhaps you meant http://
/soap/server_sa/?
Error communicating with the Netgear router

Traffic Statistics endpoint has moved on Netgear M1 MR1100

I have a Netgear M1 MR1100.

The SOAP call to urn:NETGEAR-ROUTER:service:ParentalControl:1#Authenticate succeeds, and so does, for eg, "urn:NETGEAR-ROUTER:service:DeviceInfo:1#GetAttachDevice.

When I call urn:NETGEAR-ROUTER:service:DeviceConfig:1#GetTrafficMeterStatistics I get:
501:Unsupported Action

I don't suppose anyone knows where that has moved to?

Errors and warnings filling up logs (R7800)

Hi

Thanks again for the good work.

After updating Home Assistant to 81 (from 80.3) my log is filling up...
Raspberry Pi 3, Hassbian updated yesterday. Pynetgear 0.50.
Everything running perfectly before 81. Netgear R7800 running V1.0.2.60.

device_tracker:
  - platform: netgear
    host: 192.168.30.1
    username: me ;) 
    password: !secret router
    port: 80
    interval_seconds: 15
    consider_home: 180
    new_device_defaults:
      track_new_devices: False
      hide_if_away: False

Besides the errors and warnings everything seems to work fine. Not sure what going on:

2018-10-27 15:42:16 WARNING (Thread-19) [pynetgear] Unauthorized response, let's login and retry...
2018-10-27 15:42:16 ERROR (Thread-19) [pynetgear] Invalid response
2018-10-27 15:42:16 ERROR (Thread-19) [pynetgear] Get attached devices failed
2018-10-27 15:42:16 WARNING (Thread-19) [homeassistant.components.device_tracker.netgear] Error scanning devices

(the same errors and warnings is coming up every hour or so)

A question: Will we be able to use allow_block_device in Home Assistant?

Orbis are very slow to update with accurate list of connected devices

I'm using pynetgear to pull presence information from my orbi APs (running in AP mode through a ddwrt router). Until recently it had been pretty reliable (some mis-reads but nothing terrible). A week or so after the firmware update the information pulled by pynetgear takes several hours to not ever updating presence information. The only reason I'm opening a bug here is that as soon as I access the orbis via the orbi app devices quickly move to their appropriate state when queried with pynetgear.

I don't know if there is an additional command that needs to be issued to force the update or not, but I figured I'd let you folks know.

Rebooting the orbi's makes things better for a while but it goes back to very lagged detection a few days later.

Nothing notable in pynetgear output.

This is undoubtedly caused by the recent orbi firmware update to 2.31.44, not sure if this is even something that can be fixed with pynetgear.

Willing to help debug.

Orbi details

Hardware Version | RBR20
Firmware Version | V2.3.1.44
pynetgear 0.5.2

Unexpected entry's parse errors

Hi,

I'm having trouble with parsing my devices.
All the devices show up like unexpected entry's:
Unexpected entry: ['XX:XX:XX:XX:XX:XX@7', '10.0.0.9', 'MY-PHONE']

So the devices can be read out, but I think some kind of parsing fails.
I'm using a WNDR3700v2 on latest original firmware.

Is there any way I can help fix this issue? For example can I get the raw response some way?

Thanks!

Edit:
Something a device does show up, but with invalid values in mac and name:
Device(signal=None, ip='10.0.0.13', name='&lt', mac='unknown&gt', type=None, link_rate=0)

DGN2200v4 requests can be simpler

I've tested the HTTP requests and I've found that the list of connected devices can be retrieved without authentication.
Just POST to routerlogin.net:5000/soap/server_sa/ with SOAPAction header set to "urn:NETGEAR-ROUTER:service:DeviceInfo:1#GetAttachDevice" and you get the response.
Content and all the other headers seem to be optional.

Support for WNR2000v4 / or port specification

Ok, this is not really an "issue" but perhaps it will allow pynetgear to work with the Netgear WNR2000v4 which it doesn't seem to work with.

I think NETGEAR Genie talks to the WNR2000v4 on port 5555. When I run an nmap against my WNR2000v4 I get this output:

Nmap scan report for 192.168.0.1
Host is up (0.017s latency).
Not shown: 995 closed ports
PORT STATE SERVICE
53/tcp open domain
80/tcp open http
3333/tcp open dec-notes
5555/tcp open freeciv
49152/tcp open unknown

When I ran NETGEAR Genie while watching in WireShark, I saw a lot of communication to port 5555 which I didn't see otherwise.

I think if the port can be specified, it may just work. If you allow that option I can give it a try and let you know.

Or if you have a better way of figuring it out, let me know, I'm happy to help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.