def _get_agent_spec(ipobj, interface, port):
    """take a google ipaddr object and port number and produce a net-snmp
    agent specification (see the snmpcmd manpage)"""
    if ipobj.version == 4:
        agent = 'udp:%s:%s' % (ipobj.compressed, port)
    elif ipobj.version == 6:
        if ipobj.is_link_local:
            if interface is None:
                raise RuntimeError(
                    'Cannot create agent specification from link local IPv6 address without an interface'
                    )
            else:
                agent = 'udp6:[%s%%%s]:%s' % (ipobj.compressed, interface, port
                    )
        else:
            agent = 'udp6:[%s]:%s' % (ipobj.compressed, port)
    else:
        raise RuntimeError(
            'Cannot create agent specification for IP address version: %s' %
            ipobj.version)
    return agent
