Skip to content

About

Async Python client for managed network switches over SNMP - ports, PoE, MAC address table and LLDP neighbours, which device is on which port; read-only, typed, vendor-neutral

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

aiosnmpswitch

PyPI Python Release Date Downloads
PyPI Python versions GitHub release date PyPI downloads
CI License Typed Issues Discussions
CI License Checked with mypy GitHub issues GitHub discussions
aiosnmpswitch

A Python library that reads what your managed network switches know over SNMP: ports with link, speed and traffic, PoE, the MAC address table, LLDP neighbours, trunks and spanning tree. Across several switches it works out which device is connected to which port. It only reads and never changes a setting.

It uses standard MIBs, so it is vendor-neutral; a vendor table is read only where the standard one is missing and the table was measured on that model (temperatures of the HPE Instant On 1930). HPE OfficeConnect 1920S and HPE Instant On 1930 are the tested references. It is built as a foundation for Home Assistant, but works in any asyncio program.

Documentation: aiosnmpswitch.eize.dev

Which switches work?

✅ Tested HPE OfficeConnect 1920S (JL383A, PD.02.22), HPE Instant On 1930 (JL680A, 3.4.0.0)
🟡 Expected to work Managed switches with SNMP and the standard MIBs (IF-MIB, Q-BRIDGE-MIB, LLDP-MIB)
❔ Partly Switches without LLDP or Q-BRIDGE-MIB: fewer details, no uplink detection; PoE watts per port are not in the standard MIB
❌ Not in scope Unmanaged and "smart" switches without SNMP, changing settings

Each getter returns an empty result when the switch lacks its MIB. How to report your model: Compatibility.

Quick start

You need Python 3.12 or newer and SNMP read access to the switch: SNMPv3 (recommended) or a v2c community. To locate devices across several switches, LLDP must be on on each of them.

pip install aiosnmpswitch
import asyncio

from aiosnmpswitch import AuthProtocol, PrivProtocol, SnmpSwitch, UsmAuth
from aiosnmpswitch.helpers import SwitchData, locate_macs


async def main() -> None:
    auth = UsmAuth("monitor", "auth-key", "priv-key", AuthProtocol.SHA, PrivProtocol.AES128)
    async with await SnmpSwitch.connect("192.0.2.10", auth) as switch:
        system = await switch.get_system()
        print(system.name, system.descr)
        interfaces = await switch.get_interfaces()
        for port in interfaces.values():
            print(port.name, port.oper_status, port.high_speed, port.alias)

        data = SwitchData(
            interfaces=interfaces,
            bridge_ports=await switch.get_bridge_ports(),
            fdb=await switch.get_fdb(),
            lldp=await switch.get_lldp(),
            lag_ports=await switch.get_lag_ports(),
        )
        for mac, where in locate_macs({"core": data}).items():
            print(mac, "on port", where.port_name)


asyncio.run(main())

Documentation

Roadmap

Planned work is grouped in milestones.

Contributing

Reports with your switch model and firmware help most. See CONTRIBUTING.md; for security issues SECURITY.md.

License

MIT. Provided "as is", without warranty of any kind. The icon and header images are CC BY 4.0; their source is in eizedev/brand.

About

Async Python client for managed network switches over SNMP - ports, PoE, MAC address table and LLDP neighbours, which device is on which port; read-only, typed, vendor-neutral

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages