我的firefox上安装了Autoproxy,在购买vps服务后可以通过socket5代理服务浏览每个网站。
apt-get install mercurial #on my local pc
hg clone https://vim.googlecode.com/hg/ /tmp/vim #on my local pc
abort: error: Network is unreachable
可以通过Firefox中的自动代理访问https://vim.googlecode.com/hg/。
如何在我的远程VPS上构建某种代理服务以使hg clone
命令到达https://vim.googlecode.com/hg/?
并不是所有的网站都可以在这里访问,我已经建立了一个梯形图,可以通过Firefox访问它们。
如何在我的VPS(在远程PC上)上制作另一个梯形图,以使hg clone
命令在本地PC上运行?
每次我以这种方式使用VPS和Firefox构建阶梯时:
在我的本地PC中输入ssh命令
ssh -D 127.0.0.1:1080 -p 1234 [email protected]
单击自动代理插件进入全局模式。在Socket 5代理中将其设置为良好状态。
现在我可以访问我想访问的内容。
怎么写hg clone
命令?
要使用Mercurial代理,可以在命令前添加前缀http_proxy
:
http_proxy=http://proxy-server:8080 hg clone https://vim.googlecode.com/hg
或配置~/.hgrc
为:
[http_proxy]
host=proxy-host:port
user=username
passwd=password
由于您使用的是SOCKS5代理,因此Mercurial尚不支持此功能(在撰写本文时为3.7.2),但是基于以下修补程序对其进行了扩展。
您可以下载Mercurial DVCS的一个小的扩展,以启用SOCKS5代理的使用:https : //bitbucket.org/bugheisen/socks_proxy
因此可以将您的代理配置~/.hgrc
为:
[extensions]
socks_proxy = /path/to/socks_proxy.py
[socks_proxy]
host = localhost:9150
要尝试使用SOCKS5代理,可以使用SSH的-D选项,该选项创建在SSH连接上运行的代理。或者,您可以运行Tor,这也会启动SOCKS5代理(可能在端口9050或端口9150上)。
上面的扩展基于Bug Heisen发布的原始补丁,您可以通过下载Mercurial的源代码并根据以下代码来应用此补丁来申请:
diff -r 12f161f08d74 -r 3f58227755ed mercurial/url.py
--- a/mercurial/url.py Tue Apr 01 23:41:32 2014 -0700
+++ b/mercurial/url.py Sun Apr 06 16:16:02 2014 +0200
@@ -63,6 +63,44 @@
class proxyhandler(urllib2.ProxyHandler):
def __init__(self, ui):
+
+ # First, check if a SOCKS5 proxy is set, using a line 'host = ...' in
+ # the [socks_proxy] section of the config file.
+
+ proxyurl = ui.config("socks_proxy", "host")
+
+ if proxyurl:
+ idx = proxyurl.find(":")
+ if idx < 0:
+ raise util.Abort(_("host in socks_proxy should be "
+ "hostname:port"))
+
+ host = proxyurl[:idx]
+ portstr = proxyurl[idx+1:]
+ try:
+ port = int(portstr)
+ except ValueError:
+ raise util.Abort(_("Cannot interpret '%s' in the socks_proxy "
+ "host line as an integer port number")
+ % portstr)
+
+ if port <= 0 or port > 65535:
+ raise util.Abort(_("Port number in socks_proxy host line "
+ "must lie between 1 and 65535, but is "
+ "%d") % port)
+
+ ui.note("Setting SOCKS5 proxy to %s:%d\n" % (host, port))
+
+ try:
+ import socks
+ socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, host, port)
+ socket.socket = socks.socksocket
+ except ImportError:
+ raise util.Abort(_("The SocksiPy socks module is needed for "
+ "SOCKS support"))
+
+ # Then check for a http/https proxy
+
proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
# XXX proxyauthinfo = None
然后~/.hgrc
使用socks_proxy
而不是http_proxy
(如上所示)。
关于此补丁的原始说明:
此补丁使用SocksiPy项目中的“ socks”模块(需要单独安装)增加了对SOCKS5代理的支持。由于修改了“代理处理程序”功能,因此仅适用于HTTP / HTTPS协议。对于SSH协议,通过指定
ProxyCommand
选项,可以在Mercurial之外轻松地使用SOCKS代理。该补丁中已硬编码了SOCKS5版本,但该
socks
模块也应支持其他版本。因此,其他SOCKS版本也可以相同的方式进行,但是代码需要进行修改以支持它们。出于测试目的,很高兴知道SSH可以使用
-D
命令行标志创建SOCKS5代理。使用Tor也会生成这样的代理,通常在端口9050或9150上。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句