TR-064 python API

This package provides a very lightweight and straight-forward TR-064 client, that pulls every information about supported services from the routers description files.

Note

This documentation is a work in progress. Feedback and revisions are most welcome!

Installation

Easiest way to install is to use pip:

$ python3 -m pip install tr064

To update a previous version:

$ python3 -m pip install --upgrade tr064

TR-064 API

General usage

Create a client connection to the router:

import tr064

client = tr064.Client('username', 'password', 'http://192.168.178.1:49000')

res = client.InternetGatewayDevice.DeviceInfo.GetInfo()
print(res.NewManufacturerName)

Actions (functions) are executed by append device, service and action to the client:

Client.DeviceName.ServiceName.ActionName(Arguments, ...)

If a service is offered multiple times, actions can be accessed by the zero-based square bracket operator:

Client.DeviceName.ServiceName[1].ActionName(Arguments, ...)

See more Examples.

Note

If services, actions or arguments contain a minus sign -, it must be replaced with an underscore _ and vice versa.

API

Client
class tr064.client.Client(username, password, base_url='https://192.168.178.1:49443')

TR-064 client.

Parameters:
  • username (str) – Username with access to router.
  • password (str) – Passwort to access router.
  • base_url (str) – URL to router.
Exceptions

TR-064 exceptions.

exception tr064.exceptions.TR064Exception

TR-064 base exception.

exception tr064.exceptions.TR064UnknownDeviceException

TR-064 unknown device exception.

exception tr064.exceptions.TR064UnknownServiceException

TR-064 unknown service exception.

exception tr064.exceptions.TR064UnknownServiceIndexException

TR-064 unknown service index exception.

exception tr064.exceptions.TR064UnknownActionException

TR-064 unknown action exception.

exception tr064.exceptions.TR064UnknownArgumentException

TR-064 unknown argument exception.

exception tr064.exceptions.TR064MissingArgumentException

TR-064 missing argument exception.

Note

All following classes are never used directly! They are only documented for the sake of completeness.

Device
class tr064.device.Device(xml, auth, base_url)

TR-064 device.

Parameters:
  • xml (lxml.etree.Element) – XML device element
  • auth (HTTPBasicAuthHandler) – HTTPBasicAuthHandler object, e.g. HTTPDigestAuth
  • base_url (str) – URL to router.
Service
class tr064.service.Service(auth, base_url, service_type, service_id, scpdurl, control_url, event_sub_url)

TR-064 service.

Action
class tr064.action.Action(xml, auth, base_url, name, service_type, service_id, control_url)

TR-064 action.

Parameters:
  • xml (lxml.etree.Element) – XML action element
  • auth (HTTPBasicAuthHandler) – HTTPBasicAuthHandler object, e.g. HTTPDigestAuth
  • base_url (str) – URL to router.
  • name (str) – Action name
  • service_type (str) – Service type
  • service_id (str) – Service ID
  • control_url (str) – Control URL
Helper
class tr064.attribute_dict.AttributeDict

Direct access dict entries like attributes.

class tr064.service_list.ServiceList

Service list.

Examples

All devices and services used in the following examples are taken from the TR-064 Description XML. Used actions are described in the XML refered with the SCPDURL element of each service. More details about the action can be obtained from the router manufacturer.

Devices/Services/Actions:

InternetGatewayDevice

DeviceInfo

Support urn:DeviceInfo-com:serviceId:DeviceInfo1.

GetInfo

Getting router information:

res = client.InternetGatewayDevice.DeviceInfo.GetInfo()
print('ManufacturerName', res.NewManufacturerName)
print('ManufacturerOUI', res.NewManufacturerOUI)
print('ModelName', res.NewModelName)
print('Description', res.NewDescription)
GetSecurityPort

Get port for secure access:

unsafe_client = tr064.Client('username', 'password', 'http://192.168.178.1:49000')
res = unsafe_client.InternetGatewayDevice.DeviceInfo.GetSecurityPort()

safe_client = tr064.Client('username', 'password', 'https://192.168.178.1:{}'.format(res.NewSecurityPort))

LANDevice

Hosts
GetHostNumberOfEntries/GetGenericHostEntry

List all assigned network devices:

number_of_entries = client.LANDevice.Hosts.GetHostNumberOfEntries()
for index in range(int(number_of_entries.NewHostNumberOfEntries)):
    host = client.LANDevice.Hosts.GetGenericHostEntry(NewIndex=index)
    print(host.NewIPAddress, host.NewMACAddress, host.NewHostName)
WLANConfiguration
GetInfo/SetEnable

Enable third WLAN device if not enabled:

info = client.LANDevice.WLANConfiguration[2].GetInfo()
if not bool(info.NewEnable):
    client.LANDevice.WLANConfiguration[2].SetEnable(NewEnable=1)