简体   繁体   中英

How to cause twisted based irc client to connect through socks proxy?

I'm using the markov chain irc bot based on twisted. Socks proxy may be putty, listening on port 22. Adding the following code to the above client (at the top of the py file) didn't help:

import socks, socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5,
    'localhost', 22)
socket.socket = socks.socksocket

Whereas, doing so solved the problem while using SimpleIRCClient from irclib, however irclib doesn't fit other requirements.

Thanks.

使用袜子客户端库-https: //github.com/habnabit/txsocksx

Thanks Jean-Paul Calderone. The following code worked for me.

from twisted.internet.endpoints import TCP4ClientEndpoint 
from txsocksx.client import SOCKS5ClientEndpoint

if __name__ == "__main__":
    chan = "django-hotclub"
    chain_length = 5

    myID = sys.argv[1]
    counterpartID = sys.argv[2]

    puttyEndPoint = TCP4ClientEndpoint(reactor, '127.0.0.1', 22)
    ircEndpoint = SOCKS5ClientEndpoint('irc.freenode.net', 6667, puttyEndPoint)
    d = ircEndpoint.connect(MomBotFactory('#' + chan, myID, counterpartID, chain_length, chattiness=0.05))
    reactor.run()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM