o
    jt                     @   s   d dl mZ d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
 G dd dZG d	d
 d
Zdd Zedkraeej eejdkrXedejd    ed eejd  dS dS )    )division)print_functionN)open_offline)version)
EthDecoderLinuxSLLDecoderc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )
ConnectionzThis class can be used as a key in a dictionary to select a connection
    given a pair of peers. Two connections are considered the same if both
    peers are equal, despite the order in which they were passed to the
    class constructor.
    c                 C   s   || _ || _dS )zThis constructor takes two tuples, one for each peer. The first
        element in each tuple is the IP address as a string, and the
        second is the port as an integer.
        Np1p2)selfr
   r    r   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/../../../bin/split.py__init__,   s   
zConnection.__init__c                 C   s(   d| j d | j d | jd | jd f S )zoUtility function that returns a filename composed by the IP
        addresses and ports of both peers.
        z%s.%d-%s.%d.pcapr      r	   r   r   r   r   getFilename5   s   (zConnection.getFilenamec                 C   s8   | j |j kr| j|jks| j |jkr| j|j krdS dS )Nr   r	   )r   otherr   r   r   __cmp__;   s   zConnection.__cmp__c                 C   s8   t | jd t | jd A t | jd A t | jd A S )Nr   r   )hashr
   r   r   r   r   r   __hash__B   s
   zConnection.__hash__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   %   s    	r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )Decoderc                 C   sL   |  }tj|krt | _ntj|krt | _ntd| || _i | _	d S )NzDatalink type not supported: )
datalinkpcapy
DLT_EN10MBr   decoderDLT_LINUX_SLLr   	Exceptionpcapconnections)r   pcapObjr   r   r   r   r   H   s   




zDecoder.__init__c                 C   s   | j d| j d S )Nr   )r#   looppacketHandlerr   r   r   r   startU   s   zDecoder.startc                 C   s   | j |}| }| }| | f}| | f}t||}d|j|j	f | j
vr[| }	td|	 z| j|	}
W n tjyO   td|	 Y dS w |
| j
d|j|j	f < | j
d|j|j	f  || dS )a  Handles an incoming pcap packet. This method only knows how
        to recognize TCP/IP connections.
        Be sure that only TCP packets are passed onto this handler (or
        fix the code to ignore the others).

        Setting r"ip proto 	cp" as part of the pcap filter expression
        suffices, and there shouldn't be any problem combining that with
        other expressions.
        z%s%sz%Found a new connection, storing into:zCan't write packet to:N)r    decodechild
get_ip_srcget_th_sport
get_ip_dstget_th_dportr   r
   r   r$   r   printr#   	dump_openr   	PcapErrordump)r   hdrdatapiptcpsrcdstconfndumperr   r   r   r'   Z   s"   


"zDecoder.packetHandlerN)r   r   r   r   r(   r'   r   r   r   r   r   G   s    r   c                 C   s6   t | }|d td| | f  t|  d S )Nzip proto \tcpzReading from %s: linktype=%d)r   	setfilterr/   r   r   r(   )filenamer5   r   r   r   main   s   
r?   __main__r   zUsage: %s <filename>)
__future__r   r   sysr   r   impacketr   impacket.ImpactDecoderr   r   r   r   r?   r   r/   DEPRECATION_WARNING_BANNERlenargvexitr   r   r   r   <module>   s"   ":

