
    h                         d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ g dg d	fZe
r*ej        j         ed
          ej        j        ddgg dfZddZddZddZd ZddZdS )z(
VoIP (Voice over IP) related functions
    N)sniff)IPUDP)RTP)WINDOWS)conf)sox-t.ul)-r
   ossdspz/dev/dspz*Sox must be installed to play VoIP packetsr
   r   )r   r
   	waveaudio   c                 ^   d}|}d}t          |           t          |          k    r|}n"t          |           t          |          k     r| }t          |          }t          ||z            D ],}|| ||z  ||dz   z           |||z  ||dz   z           z   z  }-| |d          ||d          |fS )N r      )lenrange)xysample_sizemssmin_r_is           V/mounts/lovelace/software/anaconda3/lib/python3.11/site-packages/scapy/modules/voip.py_merge_sound_bytesr      s     	A	BD
1vvQ	Q#a&&	TB27^^ = =	QrAvbAEl"#aQrQU|(;&<<<RSS61RSS61    c                     t          j        t          d         t          d         z   t           j        t           j                  }|j        |j        c} fd}	 |t          dd|d| n|D ]} ||                                            |                                 dS #                                  |                                 w xY w)a  Play VoIP packets with RAW data that
    are either sniffed either from an IP, or
    specified as a list.

    It will play only the incoming packets !

    :param s1: The IP of the src of all VoIP packets.
    :param lst: (optional) A list of packets to load
    :type s1: string
    :type lst: list

    :Example:

    >>> voip_play("64.2.142.189")
    while calling '411@ideasip.com'

    >>> voip_play("64.2.142.189", lst)
    with list a list of packets with VoIP data
    in their RAW layer

    .. seealso:: voip_play2
    to play both the outcoming and incoming packets
    at the same time.

    .. seealso:: voip_play3
    to read RTP VoIP packets
    r   r   stdinstdoutc                 H   | sd S |                      t                    r|                      t                    sd S |                     t                    }|j        k    rA                    |                     t          j                  j        dd                     d S d S N   )	haslayerr   r   getlayersrcwriter   	raw_layerload)pktipdsps1s     r   playzvoip_play.<locals>.playP   s     	F||C   	R(8(8 	F\\"<<IIcll4>227<===== <r   Nstoreprn )
subprocessPopensox_basePIPEr"   r#   r   close)r0   lstkargsprocrdr1   pr/   s   `      @r   	voip_playr@   /   s    : HQK(1+5Z_#-?4 4 4Dj$+GC> > > > > >;-t--u----  Q		





 			




s   "B) )*Cc                     t          | |fi |S )z0Same than voip_play, backward compatibility
    )r@   )r0   r;   r<   s      r   
voip_play1rB   c   s     R&&&&&r   c                     t          j        t          d         ddgz   t          d         z   t           j        t           j                  }|j        |j        c}dada fd}	 t          d
d|d| 	 	                                 |	                                 d	S # t          $ r Y d	S w xY w# 	 	                                 |	                                 w # t          $ r Y w w xY wxY w)z
    Same than voip_play, but will play
    both incoming and outcoming packets.
    The sound will surely suffer distortion.

    Only supports sniffing.

    .. seealso:: voip_play
    to play only incoming packets.
    r   z-c2r   r!   r   c                 "   | sd S |                      t                    r|                      t                    sd S |                     t                    }|j        |j        fv r|j        k    r5t          |                     t          j                  j	        dd          z  an4t          |                     t          j                  j	        dd          z  a
t          t          t                    \  aa
}                    |           d S d S r%   )r'   r   r   r(   r)   dstx1r   r+   r,   x2r   r*   )r-   r.   rr/   r0   s      r   r1   zvoip_play2.<locals>.play{   s     	F||C   	R(8(8 	F\\""&"&!!!v||cll4>227<<cll4>227<<*2r22IBAIIaLLLLL "!r   r2   Nr5   )r6   r7   r8   r9   r"   r#   rG   rH   r   r:   	Exception)r0   r<   r=   r>   r1   r/   s   `    @r   
voip_play2rK   i   s"    HQK4+5C",/*/K K KDj$+GC	B	B     )A4))5)))	IIKKKHHJJJJJ 	 	 	DD		IIKKKHHJJJJ 	 	 	D	sB   &B1 6(B   
B.-B.1C,3(CC,
C)&C,(C))C,c                    t          j        t          d         t          d         z   t           j        t           j                  }|j        |j        }}|fd}	 | t          dd|d| n| D ]} ||           	 |                                 |                                 dS # t          $ r Y dS w xY w# 	 |                                 |                                 w # t          $ r Y w w xY wxY w)zSame than voip_play, but made to
    read and play VoIP RTP packets, without
    checking IP.

    .. seealso:: voip_play
    for basic VoIP packets
    r   r   r!   c                     | rh|                      t                    rP|                      t                    r8|                    |                     t                    j                   d S d S d S d S N)r'   r   r   r*   r(   r,   )r-   r/   s     r   r1   zvoip_play3.<locals>.play   su     	.3<<$$ 	.c):): 	.IIcll3'',-----	. 	. 	. 	. 	. 	.r   Nr2   r5   )	r6   r7   r8   r9   r"   r#   r   r:   rJ   )r;   r<   r=   r/   r>   r1   r?   s          r   
voip_play3rO      s'    HQK(1+5Z_#-?4 4 4Dj$+C . . . .;-t--u----  Q	IIKKKHHJJJJJ 	 	 	DD		IIKKKHHJJJJ 	 	 	D	sB   "B7 <(B& &
B43B47C29(C"!C2"
C/,C2.C//C2)r   rN   )__doc__r6   scapy.sendrecvr   scapy.layers.inetr   r   scapy.layers.rtpr   scapy.constsr   scapy.configr   r8   progr	   OSErrorr   r@   rB   rK   rO   r5   r   r   <module>rX      sC       
 !           % % % % % % % %                               !  "C"C"CD
 Hy}gBCCCe,.F.F.FGH   "1 1 1 1h' ' ' '( ( (V     r   