python 2.7 - Pysnmp openServerMode with IPv6 -
i try start snmp agent pysnmp. ipv4 , ipv6 bind, works pretty fine localhost ('127.0.0.1' , '::1')
but when try use other ipv6 ip fetched interface, failed due
[vagrant@test sources]$ sudo python snmp_agent.py enp0s8 traceback (most recent call last): file "snmp_agent.py", line 172, in <module> master_agent_startup(ifname=sys.argv[1]) file "snmp_agent.py", line 101, in master_agent_startup (get_ipv6_address(interface_name), snmp_agent_port)) file "/usr/lib/python2.7/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 50, in openservermode raise error.carriererror('bind() %s failed: %s' % (iface, sys.exc_info()[1],)) pysnmp.carrier.error.carriererror: bind() ('fe80::a00:27ff:fe9e:9c16', 8001) failed: [errno 22] invalid argument
this output interface 'enp0s8':
[vagrant@test sources]$ ifconfig enp0s8 enp0s8: flags=4163<up,broadcast,running,multicast> mtu 1500 inet 172.20.20.26 netmask 255.255.255.0 broadcast 172.20.20.255 inet6 fe80::a00:27ff:fe9e:9c16 prefixlen 64 scopeid 0x20<link> ether 08:00:27:9e:9c:16 txqueuelen 1000 (ethernet) rx packets 874053 bytes 115842841 (110.4 mib) rx errors 0 dropped 0 overruns 0 frame 0 tx packets 862314 bytes 114652475 (109.3 mib) tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0
this code piece used ipv6 bind:
def get_ipv6_address(ifname): return netifaces.ifaddresses(ifname)[netifaces.af_inet6][0]['addr'].split('%')[0] config.addsockettransport(snmpengine, udp.domainname, udp.udptransport().openservermode( (get_ipv4_address(interface_name), snmp_agent_port)) ) config.addsockettransport(snmpengine, udp6.domainname, udp6.udp6sockettransport().openservermode( (get_ipv6_address(interface_name), snmp_agent_port)) )
from pysnmp sample, seems parameter inside "openservermode()" tuple of ip , port. , output error suppose there no error given ip , port. why failed due invalid argument? @ilya etingof or other pysnmp expert me it?
thanks.
update: try bind given suggestion, still doesn't work. bind command run new installed centos. still failed: [root@test ~]# ifconfig
eth1: flags=4163<up,broadcast,running,multicast> mtu 1500 inet 10.10.20.4 netmask 255.255.255.0 broadcast 10.10.20.255 inet6 fe80::f816:3eff:fee1:5475 prefixlen 64 scopeid 0x20<link> ether fa:16:3e:e1:54:75 txqueuelen 1000 (ethernet) rx packets 12242 bytes 962552 (939.9 kib) rx errors 0 dropped 0 overruns 0 frame 0 tx packets 12196 bytes 957826 (935.3 kib) tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@test ~]# python python 2.7.5 (default, oct 11 2015, 17:47:16) [gcc 4.8.3 20140911 (red hat 4.8.3-9)] on linux2 type "help", "copyright", "credits" or "license" more information. >>> import socket >>> s = socket.socket(socket.af_inet6, socket.sock_dgram, 0) >>> addr_and_port = ('fe80::f816:3eff:fedb:ba4f', 8001) >>> s.bind(addr_and_port) traceback (most recent call last): file "<stdin>", line 1, in <module> file "/usr/lib64/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [errno 22] invalid argument >>> [1]+ stopped python [root@test ~]# netstat -anp | grep 8001 [root@test ~]#
one more update: suppose bind failed due environment has issue ipv6 configuration. i'm able 1 ipv4 address using "socket.getaddrinfo()" method.
br, -dapeng jiao
you error if attempted bind same socket more once. can't see case in code.
that .openservermode()
method no magic -- calls .bind()
on socket object. inspiration, work in @ python prompt?
from pysnmp.carrier.asyncore.dgram import udp6 addr_and_port = ('fe80::a00:27ff:fe9e:9c16', 8001) udp6.udp6sockettransport().openservermode(addr_and_port)
or even:
import socket s = socket.socket(socket.af_inet6, socket.sock_dgram, 0) addr_and_port = ('fe80::a00:27ff:fe9e:9c16', 8001) s.bind(addr_and_port)
my hope tests these may figuring out problem...
Comments
Post a Comment