Search code examples
pythonnetwork-programmingcisco

Cannot print CDP Packet IP Address, but LLDP works fine


I am having an issue where I am trying to use Python's pyshark to read in IP addresses. I was able to print out the IP address of an LLDP packet just fine, using packet.lldp.mgn_addr_ip4. However packet.cdp... does not seem to have an equivalent, besides packet.cdp which returns a sequence of bytes.

I have tried packet.cdp.nrgyz.ip_address and nothing is printed out. I tried every other field from this link as well and nothing will return.

for packet in cap:
try:
    if packet.cdp:
        print(packet.cdp.nrgyz.ip_address)
    elif packet.lldp:
        print(packet.lldp.mgn_addr_ip4)
except AttributeError as e:
    pass

I'd really appreciate any kind of guidance since not a single one of the fields that says it returns an IPv4 address will print out.


Solution

  • I figured it out. Apparently you can't use cdp.nrgyz(DOT)ip_address, and instead have to use cdp.nrgyz(UNDERSCORE)ip_address. So it becomes cdp.nrgyz_ip_address, even though Wireshark documentation says it should be cdp.nrgyz.ip_address