Skip to main content

Python client to interact with SagemCom F@st routers via internal API's.

Project description

Sagemcom API Client in Python

(Unofficial) async Python client to interact with Sagemcom F@st routers via internal API's. This client offers helper functions to retrieve common used functions, but also offers functionality to do custom requests via XPATH notation.

Python 3.9+ required.

Features

  • Retrieve detailed information of your Sagemcom F@st device
  • Retrieve connected devices (wifi and ethernet)
  • Reboot Sagemcom F@st device
  • Retrieve and set all values of your Sagemcom F@st device

Supported devices

The Sagemcom F@st series is used by multiple cable companies, where some cable companies did rebrand the router. Examples are the b-box from Proximus, Home Hub from bell and the Smart Hub from BT.

Router Model Provider(s) Authentication Method Comments
Sagemcom F@st 3864 Optus sha512 username: guest, password: ""
Sagemcom F@st 3865b Proximus (b-box3) md5
Sagemcom F@st 3890V3 Delta / Zeelandnet sha512
Sagemcom F@st 3890V3 DNA (DNA Mesh Wifi F-3890) sha512 username: admin
Sagemcom F@st 3896 Ziggo1 sha512 username: admin
Sagemcom F@st 4360Air KPN md5
Sagemcom F@st 4353 Belong Gateway md5 username: admin, password: ""
Sagemcom F@st 5250 Bell (Home Hub 2000) md5 username: guest, password: ""
Sagemcom F@st 5280 sha512
Sagemcom F@st 5290 / FWR226e Frontier md5 username: admin
Sagemcom F@st 5359 KPN (Box 12) sha512 username: admin
Sagemcom F@st 5364 BT (Smart Hub) md5 username: guest, password: ""
SagemCom F@st 5366SD Eir F3000 md5
Sagemcom F@st 5370e Telia sha512
Sagemcom F@st 5380 TDC md5
Sagemcom F@st 5566 Bell (Home Hub 3000) md5 username: guest, password: ""
Sagemcom F@st 5688T Salt (FibreBox_X6) sha512 username: admin
Sagemcom F@st 5689 Bell (Home Hub 4000) md5 username: admin, password: ""
Sagemcom F@st 5689E Bell (Giga Hub) sha512 username: admin, password: ""
Sagemcom F@st 5690 Bell (Giga Hub) sha512 username: admin, password: ""
Sagemcom F@st 5655V2 MásMóvil md5
Sagemcom F@st 5657IL md5
Sagemcom F@st 5360 Sunrise Internet Box2 md5 username: admin
Speedport Pro Telekom md5 username: admin

1 The firmware provided on the Sagemcom F@st 3896 router from Ziggo does not support the endpoint used in this library. sagemcom-f3896lg-zg-api provides an API client suitable for Ziggo's firmware.

2 If you run into SSLV3_ALERT_HANDSHAKE_FAILURE errors, see here for a workaround.

Contributions welcome. If you router model is supported by this package, but not in the list above, please create an issue or pull request.

Installation

pip install sagemcom_api

Getting Started

Depending on the router model, Sagemcom is using different encryption methods for authentication, which can be found in the table above. This package supports MD5 and SHA512 encryption. If you receive a LoginTimeoutException, you will probably need to use another encryption type.

The following script can be used as a quickstart.

import asyncio
from sagemcom_api.client import SagemcomClient
from sagemcom_api.enums import EncryptionMethod
from sagemcom_api.exceptions import NonWritableParameterException

HOST = ""
USERNAME = ""
PASSWORD = ""
ENCRYPTION_METHOD = EncryptionMethod.SHA512 # or EncryptionMethod.MD5
VALIDATE_SSL_CERT = True

async def main() -> None:
    async with SagemcomClient(HOST, USERNAME, PASSWORD, ENCRYPTION_METHOD, verify_ssl=VALIDATE_SSL_CERT) as client:
        try:
            await client.login()
        except Exception as exception:  # pylint: disable=broad-except
            print(exception)
            return

        # Print device information of Sagemcom F@st router
        device_info = await client.get_device_info()
        print(f"{device_info.id} {device_info.model_name}")

        # Print connected devices
        devices = await client.get_hosts()

        for device in devices:
            if device.active:
                print(f"{device.id} - {device.name}")

        # Retrieve values via XPath notation, output is a dict
        custom_command_output = await client.get_value_by_xpath("Device/UserInterface/AdvancedMode")
        print(custom_command_output)

        # Set value via XPath notation and catch specific errors
        try:
            custom_command_output = await client.set_value_by_xpath("Device/UserInterface/AdvancedMode", "true")
        except NonWritableParameterException as exception:  # pylint: disable=broad-except
            print("Not allowed to set AdvancedMode parameter on your device.")
            return

        print(custom_command_output)

asyncio.run(main())

Functions

  • login()
  • get_device_info()
  • get_hosts()
  • get_port_mappings()
  • reboot()
  • get_value_by_xpath(xpath)
  • set_value_by_xpath(xpath, value)

Advanced

Determine the EncryptionMethod

If you are not sure which encryption method to use, you can leave it empty or pass None and use get_encryption_method to determine the encryption method.

get_encryption_method will return an EncryptionMethod when a match is found. Best would be to use this function only during your initial investigation.

This function will throw a LoginTimeoutException when no match is found, since this is still a HTTP Time Out. This could caused by the wrong encryption method, but also by trying to connect to an inaccessible host.

Handle exceptions

Some functions may cause an error when an attempt is made to execute it. These exceptions are thrown by the client and need to be handled in your Python program. Best practice is to catch some specific exceptions and handle them gracefully.

from sagemcom_api.exceptions import *

try:
    await client.set_value_by_xpath("Device/UserInterface/AdvancedMode", "true")
except NonWritableParameterException as exception:
    print("You don't have rights to write to this parameter.")
except UnknownPathException as exception:
    print("The xpath does not exist.")

Run your custom commands

Not all values can be retrieved by helper functions in this client implementation. By using XPath, you are able to return all values via the API. The result will be a dict response, or an exception when the attempt was not successful.

try:
    result = await client.get_value_by_xpath("Device/DeviceSummary")
except Exception as exception:
    print(exception)

Use your own aiohttp ClientSession

ClientSession is the heart and the main entry point for all client API operations. The session contains a cookie storage and connection pool, thus cookies and connections are shared between HTTP requests sent by the same session.

In order to change settings like the time-out, it is possible to pass your custom aiohttp ClientSession.

from aiohttp import ClientSession, ClientTimeout

session = ClientSession(timeout=ClientTimeout(100))
client = SagemcomClient(session=session)

Debugging

  • Unable to login (XMO_AUTHENTICATION_ERR)

See advanced instructions for debugging common issues.

Inspired by

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sagemcom_api-1.4.3.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sagemcom_api-1.4.3-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file sagemcom_api-1.4.3.tar.gz.

File metadata

  • Download URL: sagemcom_api-1.4.3.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sagemcom_api-1.4.3.tar.gz
Algorithm Hash digest
SHA256 ef86bc87246e1d3131a049b350b2d419c97db4afa4ec4a5dae87684d5fe3eec1
MD5 dadb581742ac355c8d905afd1033ff36
BLAKE2b-256 b699348361eccf5e13833499d3d76bad4e19a90d67f610bd53dd7c840dacf120

See more details on using hashes here.

Provenance

The following attestation bundles were made for sagemcom_api-1.4.3.tar.gz:

Publisher: release.yml on iMicknl/python-sagemcom-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sagemcom_api-1.4.3-py3-none-any.whl.

File metadata

  • Download URL: sagemcom_api-1.4.3-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sagemcom_api-1.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 79545ec3082bcb7203ea919e603a50c1cc227708874346cb938d774f65242fcd
MD5 1fc2ffdf46c077e323f80e0d5dd5461f
BLAKE2b-256 b6313761007d0ac5894dbd7765dfeff411ebf73a9b5221c0ae79e2166f06775d

See more details on using hashes here.

Provenance

The following attestation bundles were made for sagemcom_api-1.4.3-py3-none-any.whl:

Publisher: release.yml on iMicknl/python-sagemcom-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page