Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/protocols/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyc

ó
[³XMc@sãdZddlZddlZddlZddlZddlmZmZmZddl	m
Z
dejfd„ƒYZdejfd„ƒYZ
d	ejfd
„ƒYZdejfd„ƒYZd
ejfd„ƒYZdS(s)
Implementation of the SOCKSv4 protocol.
iÿÿÿÿN(treactortprotocoltdefer(tlogtSOCKSv4OutgoingcBs5eZd„Zd„Zd„Zd„Zd„ZRS(cCs
||_dS(N(tsocks(tselfR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyt__init__scCsD|jjƒ}|jjddd|jd|jƒ||j_dS(NiZitporttip(t	transporttgetPeerRt	makeReplyRthostt	otherConn(Rtpeer((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pytconnectionMades%cCs|jjjƒdS(N(RR
tloseConnection(Rtreason((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pytconnectionLostscCs|jj|ƒdS(N(Rtwrite(Rtdata((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pytdataReceived!scCs'|jj||ƒ|jj|ƒdS(N(RRR
R(RR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR$s(t__name__t
__module__RRRRR(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyRs
				tSOCKSv4IncomingcBs,eZd„Zd„Zd„Zd„ZRS(cCs||_||j_dS(N(RR(RR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR,s	cCs|jjjƒdS(N(RR
R(RR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR0scCs|jj|ƒdS(N(RR(RR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR3scCs'|jj||ƒ|jj|ƒdS(N(RRR
R(RR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR6s(RRRRRR(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR*s			tSOCKSv4cBs€eZdZded„Zd„Zd„Zd„Zd„Z	d„Z
d„Zd„Zd	d	d
d„Z
d„Zd
„ZRS(sË
    An implementation of the SOCKSv4 protocol.

    @type logging: C{str} or C{None}
    @ivar logging: If not C{None}, the name of the logfile to which connection
        information will be written.

    @type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
    @ivar reactor: The reactor used to create connections.

    @type buf: C{str}
    @ivar buf: Part of a SOCKSv4 connection request.

    @type otherConn: C{SOCKSv4Incoming}, C{SOCKSv4Outgoing} or C{None}
    @ivar otherConn: Until the connection has been established, C{otherConn} is
        C{None}. After that, it is the proxy-to-destination protocol instance
        along which the client's connection is being forwarded.
    cCs||_||_dS(N(tloggingR(RRR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyRNs	cCsd|_d|_dS(Nt(tbuftNoneR(R((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyRRs	c
Cs||jr|jj|ƒdS|j||_|j}d|jdkrx|jd |jd}|_tjd|d ƒ\}}}|jjddƒ\}|_|dd!dkrF|ddkrFd|jkrã||_dS|jjddƒ\}|_|jj|ƒ}	|	j|j	||||ƒ|	j
|d	„ƒdStj|dd!ƒ}|j	|||||ƒndS(
s…
        Called whenever data is received.

        @type data: C{str}
        @param data: Part or all of a SOCKSv4 packet.
        Ntis!BBHiiitcSs
|jdƒS(Ni[(R(tresultR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyt<lambda>rs(
RRRtstructtunpacktsplitRtresolvetaddCallbackt_dataReceived2t
addErrbacktsockett	inet_ntoa(
RRtcompleteBuffertheadtversiontcodeRtusertservertd((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyRVs*		#	
cCsò|dkstd|ƒ‚|j||||ƒsE|jdƒdS|dkr|j||t|ƒ}|j|d„ƒnG|dkr¹|jdt||ƒ}|j|d	„ƒn
t	d
|‚|j
dksîtdt|j
ƒƒ‚dS(
s3
        The second half of the SOCKS connection setup. For a SOCKSv4 packet this
        is after the server address has been extracted from the header. For a
        SOCKSv4a packet this is after the host name has been resolved.

        @type server: C{str}
        @param server: The IP address of the destination, represented as a
            dotted quad.

        @type user: C{str}
        @param user: The username associated with the connection.

        @type version: C{int}
        @param version: The SOCKS protocol version number.

        @type code: C{int}
        @param code: The comand code. 1 means establish a TCP/IP stream
            connection, and 2 means establish a TCP/IP port binding.

        @type port: C{int}
        @param port: The port number associated with the connection.
        isBad version code: %si[NicSs
|jdƒS(Ni[(R(R!R((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR"–siicSs"|\}}|jdd||ƒS(NiZi(R(t.0Rthtp((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR"™s	sBad Connect Code: %sRs hmm, still stuff in buffer... %s(tAssertionErrort	authorizeRtconnectClassRR)tlistenClasstSOCKSv4IncomingFactoryR'tRuntimeErrorRtrepr(RR1R0R.R/RR2((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR(ys

cCs |jr|jjjƒndS(N(RR
R(RR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR s	cCs!tjd||||fƒdS(Ns0code %s connection to %s:%s (user %s) authorizedi(Rtmsg(RR/R1RR0((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR7¤scGstjt||Œj||ƒS(N(Rt
ClientCreatorRt
connectTCP(RR
Rtklasstargs((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR8¨scGs/tj|||Œƒ}tj|jƒdƒS(Ni(Rt	listenTCPRtsucceedtgetHost(RRR@RAtserv((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR9«sis0.0.0.0cCsO|jjtjd|||ƒtj|ƒƒ|dkrK|jjƒndS(Ns!BBHiZ(R
RR#tpackR*t	inet_atonR(RtreplyR.RR	((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR¯s/cCs$|j||ƒ|jj|ƒdS(N(RR
R(RR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR³sc
Cs_|js
dS|jjƒ}|jjjƒ}t|jdƒ}|jdtjƒ|j|j	||krpdpsd|j|j	fƒxº|rC|d |d}}|jt
jtd„|ƒdƒdƒ|jdt
|ƒddƒxC|D];}t
t|ƒƒdkr"|jd	ƒqô|j|ƒqôW|jd
ƒqŠW|jd
ƒ|jƒdS(Ntas%s	%s:%d %s %s:%d
t<t>icSsdt|ƒS(Ns%02X(tord(tx((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR"Âst it.s
(RR
RRtopenRttimetctimeR
RtstringtjointmaptlenR<tclose(RtprotoRRt
their_peertfR5tc((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR·s(		)

N(RRt__doc__RRRRRR(RR7R8R9RRR(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR;s		#	'					tSOCKSv4FactorycBs eZdZd„Zd„ZRS(s`
    A factory for a SOCKSv4 proxy.

    Constructor accepts one argument, a log file name.
    cCs
||_dS(N(R(RR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyRÔscCst|jtƒS(N(RRR(Rtaddr((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyt
buildProtocol×s(RRR\RR_(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR]Ís	R:cBs eZdZd„Zd„ZRS(sJ
    A utility class for building protocols for incoming connections.
    cCs||_||_dS(N(RR	(RRR	((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyRás	cCss|d|jkr<d|_|jjddƒt|jƒS|jdkrOdS|jjddƒd|_dSdS(NiRiZi[(R	RRRR(RR^((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR_æs	
	(RRR\RR_(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyR:Üs	(R\R#RSR*RQttwisted.internetRRRttwisted.pythonRtProtocolRRRtFactoryR]R:(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/socks.pyt<module>s’