Similar to pyNetgear, netgear_client
provides a Go implementation of a SOAP client for communicating with Netgear routers. Unfortunately, Netgear does not release specifications for their SOAP API, so this is primarily built by reverse engineering calls.
This simple module is straight forward to test against an existing Netgear endpoint. To perform testing, the following environment variables or files are needed:
- NETGEAR_URL or .netgear_url - the http endpoint to test against. This should be your router's address. If not set, will default to "https://www.routerlogin.com", which SHOULD be intercepted by your router's DNS server.
- NETGEAR_USERNAME or .netgear_username - the username for the login operation. If not set, will default to "admin"
- NETGEAR_PASSWORD or .netgear_password - the password for the login operation
With the environment variables set, executing go test
will invoke tests for the various actions supported by the client.
The client will cache its authentication and will attempt to reauthenticate only if a call fails due to a 401 SOAP response code. Causes for such a response code are not being authenticated (yet) and expiration of the session token. If a call is made and the authentication token cannot be obtained, an error will be propagated during the call.
To create a client:
client, err := NewNetgearClient(url, insecure, username, password, timeout, debug)
Parameters:
- url - The URL of the router. If this is an empty string, it defaults to 'https://routerlogin.net'. If you are on the network and using the router for DNS, several URL's are valid. Both
http://
andhttps://
schemes have been observed to work for (www.)routerlogin.(net|com). Some products answer on port5000
. Orbi devices should also support (www.)orbilogin.(net|com). This URL should not have a trailing slash. - insecure - If the URL scheme is
https://
, this disables certificate verification. This is primarily useful if you are not using the router for DNS and instead have set theurl
parameter to an IP address. Because the certificate presented by the router does not present IP SAN entries, validation will fail. - username - The user name to use when authenticating with the router. If this is an empty string, it defaults to 'admin'.
- password - The password to use when authenticating with the router. This must be set.
- timeout - The number of seconds to use for HTTP timeout. Given that this client is primarily used for LANs, the timeout value should be set low (2) to propagate connection errors faster.
- debug - Whether to enable debug of the client itself. When set to
true
, all request and response data will be logged to STDOUT. This contains sensitive information, but can help identify errors easier.
Return:
- client - The client struct for you to make calls (listed below) with.
- err - Will be
nil
on success. Any errors encountered while attempting to create the client will be returned.
The following actions are available to a client
This will cause the client to initiate the login flow. It is not neccessary to call LogIn
before other calls because if any action detects that client is not already logged in, the LogIn
flow will automatically be handled.
Usage:
error = client.LogIn()
Return:
- err - Will be
nil
on success.
Obtains a map of k/v pairs with system statistics. The keys and values come exactly from the API with the following exceptions:
- For newer APIs, the "New" prefix is removed from the keys
NOTE: CPU utilization always seems to be 100%. This is suspected to be because gathering the statistics causes CPU strain.
Usage:
response, error = client.GetSystemInfo()
Return:
- response -
map[string]string
- Key/value pairs straight from the API - err - Will be
nil
on success.
The current keys returned, and their format is:
AvailableFlash => unknown (float)
CPUUtilization => percentage (int, see note)
PhysicalMemory => megabytes (int)
MemoryUtilization => percentage (int)
PhysicalFlash => megabytes (int)
Obtains a map of k/v pairs with traffic statistics. The keys and values come exactly from the API with the following exceptions:
- For newer APIs, the "New" prefix is removed from the keys
- Some API values contain both current and average values in the form of
current/avg
. These are split into two separate keys
Usage:
response, error = client.LogIn()
Return:
- response -
map[string]string
- Key/value pairs straight from the API - err - Will be
nil
on success.
The current keys returned, and their format is:
TodayConnectionTime => hh:mm
TodayDownload => megabytes (int?)
TodayUpload => megabytes (float)
YesterdayConnectionTime => hh:mm
YesterdayDownload => megabytes (int?)
YesterdayUpload => megabytes (float)
WeekConnectionTime => hh:mm
WeekDownload => megabytes (int?)
WeekDownloadAverage => megabytes (int?)
WeekUpload => megabytes (float)
WeekUploadAverage => megabytes (float)
MonthConnectionTime => hh:mm
MonthDownload => megabytes (int?)
MonthDownloadAverage => megabytes (int?)
MonthUpload => megabytes (float)
MonthUploadAverage => megabytes (float)
LastMonthConnectionTime => hh:mm
LastMonthDownload => megabytes (int?)
LastMonthDownloadAverage => megabytes (int?)
LastMonthUpload => megabytes (float)
LastMonthUploadAverage => megabytes (float)
Obtains an array of maps of k/v pairs with client information.
Usage:
response, error = client.GetAttachDevice()
Return:
- response -
[]map[string]string
- An array of maps containing data - err - Will be
nil
on success.
The current keys returned, and their format is:
IPAddress => address (string)
Name => name (string)
MACAddress => address (string)
ConnectionType => wired|5G|2.4G (string)
WirelessLinkSpeed => megabits/sec (int)
WirelessSignalStrength => percentage (int)
Obtains an array of maps of k/v pairs with client information exactly as-is from the API. While this call returns more data, it also takes longer indicating it may be more stressful on the router.
Usage:
response, error = client.GetAttachDevice2()
Return:
- response -
[]map[string]string
- An array of maps with key/value pairs straight from the API - err - Will be
nil
on success.
The current keys returned, and their format is:
IP => address (string)
Name => name (string)
NameUserSet => true|false (boolean)
MAC => address (string)
ConnectionType => wired|5G|2.4G (string)
SSID => name (string, sometimes empty)
Linkspeed => megabits/sec (int, sometimes empty)
SignalStrength => percentage (int, always 100 for wired)
AllowOrBlock => Allow|Block (string)
Schedule => true|false (boolean)
DeviceType => internal id (int)
DeviceTypeUserSet => true|false (boolean)
Upload => unknown (float, apparently always 0.00)
Download => unknown (float, apparently always 0.00)
QosPriority => priority (int)
Obtains a map of k/v pairs with device info. The keys and values come exactly from the API.
Usage:
response, error = client.GetDeviceInfo()
Return:
- response -
map[string]string
- Key/value pairs straight from the API - err - Will be
nil
on success.
The current keys returned, and their format is:
Description => description (string, apparently always "Netgear Smart Wizard 3.0, specification 1.6 version")
DeviceMode => mode (int)
DeviceModeCapability => capable modes (string, semicolon-separated ints, e.g., "0;1")
DeviceName => name (string)
DeviceNameUserSet => true|false (boolean)
FirewallVersion => version (string, e.g., "net-wall 2.0")
FirmwareDLmethod => protocol (string, e.g., "HTTPS")
FirmwareLastChecked => date (string, format "2023_1.28_3:15:5")
FirmwareLastUpdate => date (string, format "2023_1.28_3:15:5")
Firmwareversion => version (string, e.g., "V2.7.3.22")
FirstUseDate => date (string, format "Sunday, 30 Sep 2007 01:10:03")
ModelName => name (string)
Otherhardwareversion => version (string, apparently always "N/A")
OthersoftwareVersion => version (string, apparently always "N/A")
SerialNumber => serial number (string)
SignalStrength => strength (int)
SmartAgentversion => version (float)
VPNVersion => version (apparently always empty)