easysnmp icon indicating copy to clipboard operation
easysnmp copied to clipboard

No IPv6 support

Open fcmeurer opened this issue 9 years ago • 6 comments

If you try to use an IPv6 as hostname (such as udp6:[2801:84d:0:ab250::32:5060]), you get a

ValueError: too many values to unpack (expected 2)

as the Session object mistankely tries to unpack the ':' as the specification of a remote port.

As a quick fix I wrote two functions to detect remote ports and extract them:

def has_remote_port(hostname):
    if hostname.startswith('udp6:['):
        return ']:' in hostname

    return ':' in hostname


def extract_remote_port(hostname):
    if ']:' in hostname:
        hostname, remote_port = hostname.split(']:')
        hostname = hostname + ']'
    else:
        hostname, remote_port = hostname.split(':')

    return (hostname, int(remote_port))

And use them in the Session object constructor:

        if has_remote_port(hostname):
            if remote_port:
                raise ValueError(
                    'a remote port was specified yet the hostname appears '
                    'to have a port defined too'
                )
            else:
                hostname, remote_port = extract_remote_port(hostname)

fcmeurer avatar May 30 '16 20:05 fcmeurer

Any ETA on this? Still an issue, can't poll devices using IPv6 address.

billndotnet avatar Mar 06 '18 23:03 billndotnet

Development for this library is currently at a standstill. I do not have the time to work on it. I’m hoping someone else can pick it up and continue to work on bugs

kamakazikamikaze avatar Mar 07 '18 15:03 kamakazikamikaze

Hey guys, do we have any updates on this issue?

vyahello avatar Jan 20 '20 12:01 vyahello

Nobody has volunteered to maintain the project. No development has been done.

kamakazikamikaze avatar Jan 20 '20 17:01 kamakazikamikaze

yeah, I see last commit was about 2 years ago .. to be frank, that's so sad that such a great library has no maintainers :(

vyahello avatar Jan 20 '20 17:01 vyahello

To bypass validation on IPv6, we use this approach to work around the issue

from easysnmp import Session

session = Session(community='public', version=2, timeout=2, retries=1, use_numeric=True, use_sprint_value=True)

update hostname

session.update_session(hostname="2001:0578:0030:71c2:9552:5bd0:08d1:1f8e")

You may retrieve an individual OID using an SNMP GET

sysDescr = session.get('sysDescr.0')

print(sysDescr)

aswanikmandava avatar Apr 01 '24 13:04 aswanikmandava