File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import binascii
99import logging
1010
11+ import netaddr
12+
1113from netengine .backends import BaseBackend
1214from netengine .exceptions import NetEngineError
1315
@@ -57,6 +59,20 @@ def _octet_to_mac(self, octet_mac):
5759 )
5860 return mac_address
5961
62+ def _ascii_blocks_to_ipv6 (self , ascii_string ):
63+ """
64+ converts an ascii representation into ipv6 address
65+ """
66+ blocks = ascii_string .split ('.' )
67+ for b in range (len (blocks )):
68+ blocks [b ] = format (int (blocks [b ]), '02x' )
69+ res = netaddr .IPAddress (
70+ ':' .join (
71+ ['' .join (blocks [idx : idx + 2 ]) for idx in range (0 , len (blocks ), 2 )]
72+ )
73+ )
74+ return res
75+
6076 def _oid (self , oid ):
6177 """
6278 returns valid oid value to be passed to getCmd() or nextCmd()
Original file line number Diff line number Diff line change @@ -506,6 +506,11 @@ def neighbors(self):
506506 result = []
507507
508508 for index , neighbor in enumerate (neighbors ):
509+ oid = neighbor [0 ][0 ].getOid ()
510+ if oid [12 ] == 4 :
511+ ip = oid [13 :]
512+ else :
513+ ip = self ._ascii_blocks_to_ipv6 (str (oid [13 :]))
509514 try :
510515 mac = EUI (
511516 int (neighbor [0 ][1 ].prettyPrint (), 16 ), dialect = mac_unix_expanded
@@ -517,7 +522,12 @@ def neighbors(self):
517522 continue
518523 result .append (
519524 self ._dict (
520- {'mac' : str (mac ), 'state' : str (state ), 'interface' : str (interface )}
525+ {
526+ 'mac' : str (mac ),
527+ 'state' : str (state ),
528+ 'interface' : str (interface ),
529+ 'ip' : str (ip ),
530+ }
521531 )
522532 )
523533 return result
You can’t perform that action at this time.
0 commit comments