관리-도구
편집 파일: sockshandler.cpython-39.opt-1.pyc
a ����G2�]~������������������� ���@���s8��d�Z�ddlZddlZzddlZddlZW�n*�eyR���ddlmZ�ddlm Z�Y�n0�ddl Z dd��Zdd��Ze ��ZG�dd��dej�ZG�d d ��d ej�ZG�dd��dejej�Zed k�r4ddlZzeejd��ZW�n�eefy����dZY�n0�e�ee jde��Ze de�!d��"���#�����e de�!d��"���#�����dS�)z� SocksiPy + urllib2 handler version: 0.3 author: e<e@tr0ll.in> This module provides a Handler which you can use with urllib2 to allow it to tunnel your connection through a socks.sockssocket socket, with out monkey patching the original socket... �����Nc�����������������C���s���|�����}|�|��|S��N)�copy�update)�a�b�d��r����0/usr/lib/python3.9/site-packages/sockshandler.py� merge_dict���s���� r ���c�����������������C���sN���z6d|�v�rt��t�j|���nd|�v�r.t��|���nW�dS�W�n���Y�dS�0�dS�d�S�)N�:�.FT)�socketZ inet_ptonZAF_INET6Z inet_aton)�sr���r���r ����is_ip���s���� r���c�������������������@���s���e�Zd�Zddd�Zdd��ZdS�)�SocksiPyConnectionNTc����������� ������O���s0���||||||f|�_�tjj|�g|�R�i�|���d�S�r���)� proxyargs�httplib�HTTPConnection�__init__� �self� proxytype� proxyaddr� proxyport�rdns�username�password�args�kwargsr���r���r ���r���+���s����zSocksiPyConnection.__init__c����������� ������C���s����|�j�\}}}}}}|o|tv}z:t�|�j|�jf|�jd�||||||tjtj dff� }W�q�W�q�tj y��}�z8|r�dt|�v�r�t|�j�s�d}t� |��n��W�Y�d�}~qd�}~0�0�q||�_d�S�)N����Z0x5bF)r����socks4_no_rdns�socksZcreate_connection�host�port�timeoutr ���ZIPPROTO_TCPZTCP_NODELAYZSOCKS4Error�strr����add�sock) r���r���r���r���r���r���r���r'����er���r���r ����connect/���s�����zSocksiPyConnection.connect)NTNN��__name__� __module__�__qualname__r���r)���r���r���r���r ���r���*���s��� r���c�������������������@���s���e�Zd�Zddd�Zdd��ZdS�)�SocksiPyConnectionSNTc����������� ������O���s0���||||||f|�_�tjj|�g|�R�i�|���d�S�r���)r���r����HTTPSConnectionr���r���r���r���r ���r���D���s����zSocksiPyConnectionS.__init__c�����������������C���sx���t��|���|�jj|�j|�jd�|�_|�jjst|�jrtzt� |�j� ��|�j��W�n,�tyr���|�j�t j��|�j������Y�n0�d�S�)N)Zserver_hostname)r���r)���Z_contextZwrap_socketr'���r"���Zcheck_hostnameZ_check_hostname�sslZmatch_hostnameZgetpeercert� ExceptionZshutdownr ���Z SHUT_RDWR�close�r���r���r���r ���r)���H���s���� zSocksiPyConnectionS.connect)NTNNr*���r���r���r���r ���r.���C���s��� r.���c�������������������@���s$���e�Zd�Zdd��Zdd��Zdd��ZdS�)�SocksiPyHandlerc�����������������O���s���||�_�||�_tj�|���d�S�r���)r����kw�urllib2�HTTPHandlerr���)r���r���r���r���r���r ���r���T���s����zSocksiPyHandler.__init__c��������������������s���d��fdd� }����||�S�)Nr���c��������������������s(���t���j|�}t��j|�||d�|��}|S��N)r"���r#���r$���)r ���r5���r���r����r"���r#���r$���r���r5���Zconnr3���r���r ����buildZ���s����z(SocksiPyHandler.http_open.<locals>.build)Nr����Zdo_open�r���Zreqr:���r���r3���r ���� http_openY���s����zSocksiPyHandler.http_openc��������������������s���d��fdd� }����||�S�)Nr���c��������������������s(���t���j|�}t��j|�||d�|��}|S�r8���)r ���r5���r.���r���r9���r3���r���r ���r:���a���s����z)SocksiPyHandler.https_open.<locals>.build)Nr���r;���r<���r���r3���r ���� https_open`���s����zSocksiPyHandler.https_openN)r+���r,���r-���r���r=���r>���r���r���r���r ���r4���S���s���r4����__main__r���iZ#��Z localhostzHTTP: zhttp://httpbin.org/ipzHTTPS: zhttps://httpbin.org/ip)$�__doc__r ���r0���r6���r����ImportErrorZurllib.requestZrequestZhttp.clientZclientr!���r ���r����setr ���r���r���r/���r.���r7���ZHTTPSHandlerr4���r+����sys�int�argvr#���� ValueError� IndexErrorZbuild_openerZPROXY_TYPE_SOCKS5�opener�print�open�read�decoder���r���r���r ����<module>���s0���