Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba4234d

Browse files
committed
switching from HTTP proxy to SOCKS proxy for --tor (sick and tired of Polipo/Privoxy bull; either Tor flag is overwritten every here and there or they are putting all kinds of filter warnings)
1 parent 8ea9b19 commit ba4234d

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

lib/core/option.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from extra.keepalive import keepalive
2727
from extra.oset.pyoset import oset
28+
from extra.socks import socks
2829
from lib.controller.checks import checkConnection
2930
from lib.core.common import Backend
3031
from lib.core.common import dataToStdout
@@ -1674,11 +1675,21 @@ def __setTrafficOutputFP():
16741675

16751676
conf.trafficFP = openFile(conf.trafficFile, "w+")
16761677

1677-
def __setTorProxySettings():
1678+
def __setTorSocksProxySettings():
16781679
if not conf.tor:
16791680
return
16801681

1681-
infoMsg = "setting Tor proxy settings"
1682+
infoMsg = "setting Tor SOCKS proxy settings"
1683+
logger.info(infoMsg)
1684+
1685+
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, 'localhost', 9050)
1686+
socks.wrapmodule(urllib2)
1687+
1688+
def __setTorHTTPProxySettings():
1689+
if not conf.tor:
1690+
return
1691+
1692+
infoMsg = "setting Tor HTTP proxy settings"
16821693
logger.info(infoMsg)
16831694

16841695
found = None
@@ -1852,7 +1863,7 @@ def init(inputOptions=AttribDict(), overrideOptions=False):
18521863
__cleanupOptions()
18531864
__checkDependencies()
18541865
__basicOptionValidation()
1855-
__setTorProxySettings()
1866+
__setTorSocksProxySettings()
18561867
__setMultipleTargets()
18571868
__setTamperingFunctions()
18581869
__setTrafficOutputFP()

lib/request/connect.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import urlparse
1616
import traceback
1717

18+
from extra.socks.socks import GeneralProxyError
1819
from extra.multipart import multipartpost
20+
1921
from lib.core.agent import agent
2022
from lib.core.common import asciifyUrl
2123
from lib.core.common import average
@@ -92,10 +94,20 @@ def __retryProxy(**kwargs):
9294
warnMsg += "lower the --time-sec value (e.g. --time-sec=2)"
9395
singleTimeWarnMessage(warnMsg)
9496
elif kb.originalPage is None:
95-
warnMsg = "if the problem persists please check that the provided "
96-
warnMsg += "target url is valid. If it is, you can try to rerun "
97-
warnMsg += "with the --random-agent switch turned on "
98-
warnMsg += "and/or proxy switches (--ignore-proxy, --proxy,...)"
97+
if conf.tor:
98+
warnMsg = "please make sure that you have "
99+
warnMsg += "Tor installed and running so "
100+
warnMsg += "you could successfully use "
101+
warnMsg += "--tor switch "
102+
if IS_WIN:
103+
warnMsg += "(e.g. https://www.torproject.org/download/download.html.en)"
104+
else:
105+
warnMsg += "(e.g. https://help.ubuntu.com/community/Tor)"
106+
else:
107+
warnMsg = "if the problem persists please check that the provided "
108+
warnMsg += "target url is valid. If it is, you can try to rerun "
109+
warnMsg += "with the --random-agent switch turned on "
110+
warnMsg += "and/or proxy switches (--ignore-proxy, --proxy,...)"
99111
singleTimeWarnMessage(warnMsg)
100112
elif conf.threads > 1:
101113
warnMsg = "if the problem persists please try to lower "
@@ -440,7 +452,7 @@ def getPage(**kwargs):
440452
processResponse(page, responseHeaders)
441453
return page, responseHeaders, code
442454

443-
except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead), e:
455+
except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, GeneralProxyError), e:
444456
tbMsg = traceback.format_exc()
445457

446458
if "no host given" in tbMsg:

0 commit comments

Comments
 (0)