
     ci                         d Z ddlZddlZddlZddlmZ ddlmZ dZdZde	de
fd	Zeeddd
de	de	dedee	   deej                     ddfdZde	defdZddeee	      ddfdZedk(  r e        yy)z6
Small module for use with the wake on lan protocol.

    N)List)Optionalz255.255.255.255	   
macaddressreturnc                     t        |       dk(  r| d   }| j                  |d      } n%t        |       dk(  r| d   }| j                  |d      } t        |       dk7  rt        d      t        j	                  d| d	z  z         S )
a2  
    Create a magic packet.

    A magic packet is a packet that can be used with the for wake on lan
    protocol to wake up a computer. The packet is constructed from the
    mac address given as a parameter.

    Args:
        macaddress: the mac address that should be parsed into a magic packet.

                    zIncorrect MAC address formatFFFFFFFFFFFF   )lenreplace
ValueErrorbytesfromhex)r   seps     N/var/www/newjin.ru/wol/venv/lib/python3.12/site-packages/wakeonlan/__init__.pycreate_magic_packetr      s     :"m''R0
	ZB	m''R0

:"788==JO344    
ip_addressport	interfaceaddress_familymacsr   r   r   r   c                    |D cg c]  }t        |       }}|+t        |       rt        j                  nt        j                  }t        j                  |t        j
                        5 }||j                  |df       |j                  t        j                  t        j                  d       |j                  | |f       |D ]  }|j                  |        	 ddd       yc c}w # 1 sw Y   yxY w)ab  
    Wake up computers having any of the given mac addresses.

    Wake on lan must be enabled on the host device.

    Args:
        macs: One or more macaddresses of machines to wake.

    Keyword Args:
        ip_address: the ip address of the host to send the magic packet to.
        port: the port of the host to send the magic packet to.
        interface: the ip address of the network adapter to route the magic packet through.
        address_family: the address family of the ip address to initiate connection with.
            When not specificied, chosen automatically between IPv4 and IPv6.

    Nr      )r   _is_ipv6_addresssocketAF_INET6AF_INET
SOCK_DGRAMbind
setsockopt
SOL_SOCKETSO_BROADCASTconnectsend)	r   r   r   r   r   macpacketssockpackets	            r   send_magic_packetr1   (   s    . 488C"3'8G8/
;FOO 	 
~v'8'8	9 T IIy!n%))6+>+>Bj$'( 	FIIf	  9 s   C$*A0C))C2c                 |    	 t        t        j                  |       t        j                        S # t        $ r Y yw xY w)NF)
isinstance	ipaddressr   IPv6Addressr   )r   s    r   r"   r"   O   s7    )..z:I<Q<QRR s   ,/ 	;;argvc                     t        j                  dt         j                        }|j                  dddd       |j                  dd	d
d       |j                  ddt        d       |j                  ddt
        t        d       |j                  dddd       |j                  |       }t        |j                  |j                  |j                  |j                  |j                  rt        j                  ndd y)z0
    Run wake on lan as a CLI application.

    z:Wake one or more computers using the wake on lan protocol.)descriptionformatter_classr   zmac address+z:The mac addresses of the computers you are trying to wake.)metavarnargshelpz-6use_ipv6
store_truez>To indicate if ipv6 should be used by default instead of ipv4.)destactionr=   z-iipz7The ip address of the host to send the magic packet to.)r;   defaultr=   z-pr   z1The port of the host to send the magic packet to.)r;   typerC   r=   z-nr   NzHThe ip address of the network adapter to route the magic packet through.r   )argparseArgumentParserArgumentDefaultsHelpFormatteradd_argumentBROADCAST_IPintDEFAULT_PORT
parse_argsr1   r   ipnr>   r#   r$   )r6   parserargss      r   mainrR   V   s   
 $$P >>F I	   M	   F	   @   W	   T"D	66VV&&*.--vTr   __main__)N)__doc__rE   r4   r#   typingr   r   rI   rK   strr   r   rJ   AddressFamilyr1   boolr"   rR   __name__ r   r   <module>r[      s         !5C 5E 52 ##59$$$ $ }	$
 V112$ 
$N  /xS	" /d /d zF r   