Defragment IP packets 'on-the-flow'. Usage: >>> sniff(session=IPSession)
| 64 | |
| 65 | |
| 66 | class IPSession(DefaultSession): |
| 67 | """Defragment IP packets 'on-the-flow'. |
| 68 | |
| 69 | Usage: |
| 70 | >>> sniff(session=IPSession) |
| 71 | """ |
| 72 | |
| 73 | def __init__(self, *args, **kwargs): |
| 74 | # type: (*Any, **Any) -> None |
| 75 | DefaultSession.__init__(self, *args, **kwargs) |
| 76 | self.fragments = defaultdict(list) # type: DefaultDict[Tuple[Any, ...], List[Packet]] # noqa: E501 |
| 77 | |
| 78 | def process(self, packet: Packet) -> Optional[Packet]: |
| 79 | from scapy.layers.inet import IP, _defrag_ip_pkt |
| 80 | if not packet: |
| 81 | return None |
| 82 | if IP not in packet: |
| 83 | return packet |
| 84 | return _defrag_ip_pkt(packet, self.fragments)[1] # type: ignore |
| 85 | |
| 86 | |
| 87 | class StringBuffer(object): |
no outgoing calls
no test coverage detected