• File: socks.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/__pycache__/socks.cpython-37.pyc
  • Date Modified: 07/08/2021 12:07 AM
  • File size: 20.95 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

"@Wu	@sdZdZddlZddlZddlmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZd	ZZd
ZZdZZeeedZeeeeZejZZGd
ddeZGdddeZ GdddeZ!GdddeZ"GdddeZ#GdddeZ$GdddeZ%ddddZ&dd d!d"d#d$d%d&d'Z'ed(ed(ed)iZ(d:d+d,Z)e)Z*d-d.Z+e+Z,d/d0Z-e-Z.d;d1d2Z/Gd3d4d4ejZ0d5d6Z1xBd7D]:Z2e3e0e2dZ4e5e4e
se0j67e2e8e0e2e1e2qWGd8d9d9e0Z9dS)<a

SocksiPy - Python SOCKS module.
Version 1.5.7

Copyright 2006 Dan-Haim. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
3. Neither the name of Dan Haim nor the names of his contributors may be used
   to endorse or promote products derived from this software without specific
   prior written permission.

THIS SOFTWARE IS PROVIDED BY DAN HAIM "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL DAN HAIM OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMANGE.


This module provides a standard socket-like interface for Python
for tunneling connections through SOCKS proxies.

===============================================================================

Minor modifications made by Christopher Gilbert (http://motomastyle.com/)
for use in PyLoris (http://pyloris.sourceforge.net/)

Minor modifications made by Mario Vilas (http://breakingcode.wordpress.com/)
mainly to merge bug fixes found in Sourceforge

Modifications made by Anorov (https://github.com/Anorov)
-Forked and renamed to PySocks
-Fixed issue with HTTP proxy failure checking (same bug that was in the old ___recvall() method)
-Included SocksiPyHandler (sockshandler.py), to be used as a urllib2 handler,
 courtesy of e000 (https://github.com/e000): https://gist.github.com/869791#file_socksipyhandler.py
-Re-styled code to make it readable
    -Aliased PROXY_TYPE_SOCKS5 -> SOCKS5 etc.
    -Improved exception handling and output
    -Removed irritating use of sequence indexes, replaced with tuple unpacked variables
    -Fixed up Python 3 bytestring handling - chr(0x03).encode() -> b""
    -Other general fixes
-Added clarification that the HTTP proxy connection method only supports CONNECT-style tunneling HTTP proxies
-Various small bug fixes
z1.5.7N)
EOPNOTSUPPEINVALEAGAIN)BytesIO)SEEK_CUR)Callable)	b64encode)SOCKS4SOCKS5HTTPc@s"eZdZdZdddZddZdS)
ProxyErrorz>
    socket_err contains original socket.error exception.
    NcCs(||_||_|r$|jd|7_dS)Nz: {0})msg
socket_errformat)selfrrr6/opt/alt/python37/lib/python3.7/site-packages/socks.py__init__NszProxyError.__init__cCs|jS)N)r)rrrr__str__UszProxyError.__str__)N)__name__
__module____qualname____doc__rrrrrrrJs
rc@seZdZdS)GeneralProxyErrorN)rrrrrrrrXsrc@seZdZdS)ProxyConnectionErrorN)rrrrrrrrYsrc@seZdZdS)SOCKS5AuthErrorN)rrrrrrrrZsrc@seZdZdS)SOCKS5ErrorN)rrrrrrrr[src@seZdZdS)SOCKS4ErrorN)rrrrrrrr \sr c@seZdZdS)	HTTPErrorN)rrrrrrrr!]sr!zRequest rejected or failedzLRequest rejected because SOCKS server cannot connect to identd on the clientzPRequest rejected because the client program and identd report different user-ids)[\]zGeneral SOCKS server failurez!Connection not allowed by rulesetzNetwork unreachablezHost unreachablezConnection refusedzTTL expiredz(Command not supported, or protocol errorzAddress type not supported)r	r
ri8iTcCs.|||||r|nd|r"|ndft_dS)z
    set_default_proxy(proxy_type, addr[, port[, rdns[, username, password]]])

    Sets a default proxy which all further socksocket objects will use,
    unless explicitly changed. All parameters are as for socket.set_proxy().
    N)encode
socksocket
default_proxy)
proxy_typeaddrportrdnsusernamepasswordrrrset_default_proxyssr3cCstjS)z>
    Returns the default proxy, set by set_default_proxy.
    )r+r,rrrrget_default_proxysr4cCstjrt|j_ntddS)a"
    Attempts to replace a module's socket library with a SOCKS socket. Must set
    a default proxy using set_default_proxy(...) first.
    This will only work on modules that import socket directly into the namespace;
    most of the Python Standard Library falls into this category.
    zNo default proxy specifiedN)r+r,socketr)modulerrrwrap_modules
r7c
CsH|\}
}|
dr|
d}
|r4|dr4|d}d}xt||dtjD]}
|
\}}}}}d}yt|||}|	dk	rx|	D]}|j|q~Wt|tt	fr|
||dk	r||||||||dk	r|||
|
|f|Stjk
r&}z|}|dk	r|d}Wdd}~XYqLXqLW|dk	r:|tddS)acreate_connection(dest_pair, *[, timeout], **proxy_args) -> socket object

    Like socket.create_connection(), but connects to proxy
    before returning the socket object.

    dest_pair - 2-tuple of (IP/hostname, port).
    **proxy_args - Same args passed to socksocket.set_proxy() if present.
    timeout - Optional socket timeout value, in seconds.
    source_address - tuple (host, port) for the socket to bind to as its source
    address before connecting (only for compatibility)
    [z[]Nrzgai returned empty list.)
startswithstripr5getaddrinfoSOCK_STREAMr+Z
setsockopt
isinstanceintfloatZ
settimeout	set_proxybindconnecterrorclose)	dest_pairr-
proxy_addr
proxy_portZ
proxy_rdnsZproxy_usernameZproxy_passwordZtimeoutZsource_addressZsocket_optionsZremote_hostZremote_porterrrfamilyZsocket_typeprotoZ	canonnameZsaZsockopterrrcreate_connections>







rNc@seZdZdZddZeZdS)_BaseSocketzJAllows Python 2's "delegated" methods such as send() to be overridden
    cOsHtj|f||t|_x(|jD]}t|||j|<t||q"WdS)N)_orig_socketrdict
_savedmethods
_savenamesgetattrdelattr)rposkwnamerrrrs
z_BaseSocket.__init__N)rrrrrlistrSrrrrrOsrOcsfddS)Ncs|j||S)N)rR)rrVrW)rXrr<lambda>z_makemethod.<locals>.<lambda>r)rXr)rXr_makemethodsr\)sendtosendrecvfromrecvc@seZdZdZdZejejdfddZddZ	d-d	d
Z
e
ZddZd
dZ
d.ddZd/ddZddZddZddZeZddZeZddZeZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zeeeee eiZ!d)d*Z"d+d,Z#dS)0r+a2socksocket([family[, type[, proto]]]) -> socket object

    Open a SOCKS enabled socket. The parameters are the same as
    those of the standard socket init. In order for SOCKS to work,
    you must specify family=AF_INET and proto=0.
    The "type" argument must be either SOCK_STREAM or SOCK_DGRAM.
    NrcOsf|tjtjfkr"d}t||tj||||f||d|_|jrP|j|_	nd|_	d|_
d|_dS)Nz0Socket type must be stream or datagram, not {!r})NNNNNN)r5r<
SOCK_DGRAM
ValueErrorrrOr
_proxyconnr,proxyproxy_socknameproxy_peername)rrJtyperKargskwargsrrrrrs
zsocksocket.__init__cCs@d}x6t||kr:||t|}|s0td||7}qW|S)z
        Receive EXACTLY the number of bytes requested from the file object.
        Blocks until the required number of bytes have been received.
        r[zConnection closed unexpectedly)lenreadr)rfilecountdatadrrr_readallszsocksocket._readallTcCs.|||||r|nd|r"|ndf|_dS)aset_proxy(proxy_type, addr[, port[, rdns[, username[, password]]]])
        Sets the proxy to be used.

        proxy_type -    The type of the proxy to be used. Three types
                        are supported: PROXY_TYPE_SOCKS4 (including socks4a),
                        PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP
        addr -        The address of the server (IP or DNS).
        port -        The port of the server. Defaults to 1080 for SOCKS
                       servers and 8080 for HTTP proxy servers.
        rdns -        Should DNS queries be performed on the remote side
                       (rather than the local side). The default is True.
                       Note: This has no effect with SOCKS4 servers.
        username -    Username to authenticate with to the server.
                       The default is no authentication.
        password -    Password to authenticate with to the server.
                       Only relevant when username is also provided.
        N)r*rd)rr-r.r/r0r1r2rrrr@szsocksocket.set_proxycOs|j\}}}}}}|r"|jtjkr4tj|f||S|jrFttd|t	kr^d}	tt
|	tj|f|||\}
}d|f}t|_|
}
|j|
d}||j||\}
}|
\}}
|\}
}t|||fd|_dS)zm
        Implements proxy connection for UDP sockets,
        which happens during the bind() phase.
        z"Socket already bound to an addressz'UDP only supported by SOCKS5 proxy type0)z0.0.0.0rN)rdrgr5rarPrArcrCrr
rrOZgetsockname_proxy_addrrB_SOCKS5_requestre)rrVrWr-rFrGr0r1r2r_r/dstrdZ
UDP_ASSOCIATEZrelayhostrrrrA*s(zsocksocket.bindc
Os|jtjkr tj||f||S|js0|d|d}|dd}t}d}||d}|||	||tj
|||f||}	|	|S)N)rs)
rgr5rarOr]rcrArwrite_write_SOCKS5_addressr^getvaluetell)
rbytesrhriZaddressflagsheaderZRSVZ
STANDALONEZsentrrrr]Ns


zsocksocket.sendtocKs6|jtjkr |j|||jf|Stj|||f|SdS)N)rgr5rar]rfrOr^)rrrrirrrr^aszsocksocket.sendc	Cs|jtjkrt|||S|js*|dtt|||}|	dt
|d}t|rbt
d||\}}|jr|j\}}||ks|d|fkrttd|||ffS)N)rxrr
r	zReceived UDP packet fragmentrzPacket filtered)rgr5rarOr_rcrArr`seekrrkordNotImplementedError_read_SOCKS5_addressrfrCr)	rbufsizerZbufZfragZfromhostZfromportZpeerhostZpeerportrrrr_gs


zsocksocket.recvfromcOs|j||\}}|S)N)r_)rrVrWrrurrrr`{szsocksocket.recvcCs|jr|jt|S)N)rcrDrO)rrrrrDs
zsocksocket.closecCs|jS)zL
        Returns the bound IP address and port number at the proxy.
        )re)rrrrget_proxy_socknameszsocksocket.get_proxy_socknamecCs
t|S)z>
        Returns the IP and port number of the proxy.
        )rOgetpeername)rrrrget_proxy_peernameszsocksocket.get_proxy_peernamecCs|jS)z
        Returns the IP address and port number of the destination
        machine (note: get_proxy_peername returns the proxy)
        )rf)rrrrget_peernameszsocksocket.get_peernamecGsd}||||\|_|_dS)zI
        Negotiates a stream connection through a SOCKS5 server.
        N)rtrfre)r	dest_addrZCONNECTrrr_negotiate_SOCKS5szsocksocket._negotiate_SOCKS5cCs|j\}}}}}}	|d}
|dd}z|r@|	r@|
dn
|
d|
||d}|dddkrvtd	|ddd
kr|
dtt||tt|	|	|
||d}
|
dddkrtd	|
dddkrt	d
n6|dddkr4|dddkr,t	dntd	|
d|d|
||
}|
||d}|dddkrtd	t|dd}|dkrt
|d}td||||}||fS||
XdS)z
        Send SOCKS5 request with given command (CMD field) and
        address (DST field). Returns resolved DST address that was used.
        wbrbrssr
r	z%SOCKS5 proxy server sent invalid datarrzzSOCKS5 authentication failedz7All offered SOCKS5 authentication methods were rejectedrz
Unknown errorz
{0:#04x}: {1}N)rdmakefiler{flushrprchrrjr*rr|r
SOCKS5_ERRORSgetrrrrD)rZconncmdrvr-r.r/r0r1r2writerreaderZchosen_authZauth_statusZresolvedrespstatusrCZbndrrrrtsL

.



zsocksocket._SOCKS5_requestc	CsH|\}}|j\}}}}}}	tjdtjdi}
xrtjtjfD]b}yDt||}||
||t||}|td|||fStj	k
rw8Yq8Xq8W|r|
d}
|dtt|

|
nbt
||tjtjtjtj}|d}|d}|dd}t||}||
||t||}|td|||fS)z~
        Return the host and port packed for the SOCKS5 protocol,
        and the resolved address as a tuple object.
        rz>Hidnarrrr%)rdr5AF_INETAF_INET6Z	inet_ptonr{	inet_ntopstructpackrCr*rrjr;Z	AF_UNSPECr<ZIPPROTO_TCPZ
AI_ADDRCONFIG)rr.rlrwr/r-rur0r1r2Zfamily_to_byterJ
addr_bytesZ
host_bytesZ	addressesZtarget_addrrrrr|s0
 z socksocket._write_SOCKS5_addresscCs||d}|dkr(t||d}nN|dkrN||d}||t|}n(|dkrnttj||d}ntdtd||d	d
}||fS)Nr	rr%rrrz%SOCKS5 proxy server sent invalid dataz>Hr
r)	rpr5	inet_ntoarrrrrunpack)rrlZatypr.lengthr/rrrr!szsocksocket._read_SOCKS5_addresscCs|j\}}}}}}|d}	|dd}
zLd}yt|}Wn4tjk
rr|r^d}d}ntt|}YnX|	tddd	||	||r|	||	d
|r|	|	dd
|	
||
d}
|
dd	d
krtd
t
|
d	d}|dkr&t|d}td||t|
ddtd|
dddf|_|rjt||f|_n
||f|_Wd|
|	XdS)zB
        Negotiates a connection through a SOCKS4 server.
        rrrFsTz>BBHr%r	rzrr)z%SOCKS4 proxy server sent invalid datar
Zz
Unknown errorz
{0:#04x}: {1}Nz>H)rdrr5Z	inet_atonrC
gethostbynamer{rrr*rrprr
SOCKS4_ERRORSrr rrrrerfrD)rr	dest_portr-r.r/r0r1r2rrZremote_resolverrrrCrrr_negotiate_SOCKS40sB




,zsocksocket._negotiate_SOCKS4cCsj|j\}}}}}}|r|nt|}d|ddt|dd|dg}	|rv|rv|	dt|d||	d|d|	|	}
|

}|
|stdy|
d	d
\}}
}Wntk
rtdYnX|dstd
yt|
}
Wntk
r$tdYnX|
dkrVd|
|}|
dkrN|d7}t|d|_||f|_dS)z
        Negotiates a connection through an HTTP server.
        NOTE: This currently only supports HTTP CONNECT-style proxies.
        sCONNECT r:s	 HTTP/1.1sHost: sProxy-Authorization: basic s
zConnection closed unexpectedly r
z'HTTP proxy server sent invalid responsezHTTP/z0Proxy server does not appear to be an HTTP proxyz4HTTP proxy server did not return a valid HTTP statusz{0}: {1})iiiza
[*] Note: The HTTP proxy server may not be supported by PySocks (must be a CONNECT tunnel proxy))s0.0.0.0rN)rdr5rr*strappendrZsendalljoinrreadlinerDrsplitrbr9r>r!rrerf)rrrr-r.r/r0r1r2Zhttp_headersZfobjZstatus_linerKZstatus_codeZ
status_msgrCrrr_negotiate_HTTPks< 



zsocksocket._negotiate_HTTPc
Cst|dks|ddr$td|\}}|jtjkrt|jsH|dt|}|dkrf|sfd|_	n
||f|_	dS|j
\}}}}}}	t|tt
frt|dks|rt|tstd|dkr||_	t|||fdS|}yt||Wn`tjk
rP}
z>||\}}d	||}t|}d
||}
t|
|
Wdd}
~
XYntXy|j|}||||WnVtjk
r}
z|td|
Wdd}
~
XYn tk
r|YnXdS)z
        Connects to the specified destination through a proxy.
        Uses the same API as socket's connect().
        To select the proxy server, use set_proxy().

        dest_pair - 2-tuple of (IP/hostname, port).
        r
rr8zPySocks doesn't support IPv6)rxrz0.0.0.0Nz0Invalid destination-connection (host, port) pairz{0}:{1}z!Error connecting to {0} proxy {1}zSocket error)rjr9r5rCrgrarcrArrfrdr=rYtupler>rrOrBrsrDrPRINTABLE_PROXY_TYPESr_proxy_negotiatorsr)rrErrr-rFrGr0r1r2rCZproxy_serverZprintable_typerZ	negotiaterrrrBsR





zsocksocket.connectcCs4|j\}}}}}}|pt|}|s,td||fS)zD
        Return proxy address to connect to as tuple object
        zInvalid proxy type)rd
DEFAULT_PORTSrr)rr-rFrGr0r1r2rrrrss
zsocksocket._proxy_addr)NNNTNN)r)r)$rrrrr,r5rr<rrpr@ZsetproxyrAr]r^r_r`rDrZgetproxysocknamerZgetproxypeernamerrrrtr|rrrrr
rrrBrsrrrrr+s:
$

R*;7Mr+)NNNTNN)	NNNTNNNNN):r__version__r5rerrnorrriorosrcollectionsrbase64rZPROXY_TYPE_SOCKS4rZPROXY_TYPE_SOCKS5r
ZPROXY_TYPE_HTTPrZPROXY_TYPESrQzipvalueskeysrZ
_orgsocketrPIOErrorrrrrrr r!rrrr3Zsetdefaultproxyr4Zgetdefaultproxyr7Z
wrapmodulerNrOr\rXrTmethodr=rSrsetattrr+rrrr<module>5sl


7