Skip to content

TypeError: unhashable type: 'RandIP' when running pkt.summary() when pkt IP packet has RandIP #4883

@lpenz

Description

@lpenz

Brief description

When a pkt packet has an IP layer uses RandIP, calling pkt.summary() gives the TypeError: unhashable type: 'RandIP' error.

Scapy version

e73137e

Python version

3.12.3

Operating system

6.14.0

Additional environment information

Tested in various other environments.

How to reproduce

$ python
Python 3.12.3 (main, Nov  6 2025, 13:44:16) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from scapy.all import *
>>> pkt = IP(dst=RandIP())
>>> pkt.summary()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "scapy/scapy/packet.py", line 1710, in summary
    return self._do_summary()[1]
           ^^^^^^^^^^^^^^^^^^
  File "/scapy/scapy/packet.py", line 1687, in _do_summary
    ret = self.mysummary()
          ^^^^^^^^^^^^^^^^
  File "scapy/scapy/layers/inet.py", line 627, in mysummary
    s = self.sprintf("%IP.src% > %IP.dst% %IP.proto%")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "scapy/scapy/packet.py", line 1650, in sprintf
    elif cls == self.__class__.__name__ and hasattr(self, fld):
                                            ^^^^^^^^^^^^^^^^^^
  File "scapy/scapy/packet.py", line 504, in __getattr__
    return v if isinstance(v, RawVal) else fld.i2h(self, v)
                                           ^^^^^^^^^^^^^^^^
  File "scapy/scapy/fields.py", line 935, in i2h
    x = self.__findaddr(pkt)
        ^^^^^^^^^^^^^^^^^^^^
  File "scapy/scapy/fields.py", line 924, in __findaddr
    return pkt.route()[1] or conf.route.route()[1]
           ^^^^^^^^^^^
  File "scapy/scapy/layers/inet.py", line 580, in route
    return conf.route.route(dst, dev=scope)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "scapy/scapy/route.py", line 187, in route
    if (dst, dev) in self.cache:
       ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'RandIP'
>>> 

Actual result

No response

Expected result

I'd expect each call to pkt.summary() to show a different IP.

I'm guessing we shouldn't look at the cache before rendering the IP.

pkt.show2() works as expected.

Related resources

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions