WHY的博客

  • 首页

  • 标签

  • 分类

  • 归档

  • 搜索

让命令行走代理的方法

发表于 2018-07-25 | 更新于 2019-02-03 | 分类于 系统相关

前言

这个博客自从春节开始就没有更新过,不知不觉就到了大一结束的暑假了,今天突然有兴趣看一看自己的博客,改一改主题,加一加插件,结果刚想把博客从Github clone到本地

1
git clone https://github.com/00why00/00why00.github.io.git

clone速度从17Kib/s慢慢变成3Kib/s

到最后,结果显示

1
fatal: unable to access 'https://github.com/00why00/00why00.github.io.git': Proxy CONNECT aborted

检查自己的ssr,改成全局模式,仍然不行,遂Google

原因

暂时不明

经实验发现如下几个特点:

1、ShadowSocksR 这类工具尽管开启了全局代理,但是 cmd 里依旧无法下载成功。

2、这种全局代理只针对使用IE代理的程序才全局,不是像VPN那样的全局。当然也更不支持PAC模式。

解决办法

经过对大量他人博客的查看与思考,经过无数次失败之后,我终于总结出来了正确的方法

让 cmd 走代理的方法

在 cmd 中执行以下命令

1
set ALL_PROXY=socks5://127.0.0.1:1080

1、因为Shadowsocks是一种基于Socks5代理方式的加密传输协议(见Wiki),所以必须为sock5而不是某些博客所说的http。

2、因为 ssr 代理端口为1080,所以其端口号不应设置为某些博客所说的8080等。

3、如果你的代理服务器要求用户名和密码的话,那么还需要:

1
2
set http_proxy_user=
set http_proxy_pass=

设置完成后,就可以在 cmd 下正常使用网络了。

让 git 走代理的方法

同理,在 git bush 中执行以下命令

1
2
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080

如果需要用户名密码的话,则设置:

1
2
git config –global http.proxy http://user:password@socks5://127.0.0.1:1080
git config –global https.proxy http://user:password@socks5://127.0.0.1:1080

其中 user 和 password 分别为你的用户名和密码。

设置完成后,可以通过如下命令来查看设置是否生效:

1
git config –get –global http.proxy

如果某一天你不喜欢她了,需要删除代理设置,那么可以使用:

1
2
git config --global (或 --system 或 --local) --unset http.proxy
git config --global (或 --system 或 --local) --unset https.proxy

来删除设置。

让 powershell 走代理的方法

从 Microsoft 的脚本中心下载的脚本,未经实验,请谨慎使用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<#
.Synopsis
This function will set the proxy settings provided as input to the cmdlet.
.Description
This function will set the proxy server and (optinal) Automatic configuration script.
.Parameter ProxyServer
This parameter is set as the proxy for the system.
Data from. This parameter is Mandatory
.Example
Setting proxy information
Set-InternetProxy -proxy "proxy:7890"
.Example
Setting proxy information and (optinal) Automatic Configuration Script
Set-InternetProxy -proxy "proxy:7890" -acs "http://proxy:7892"
#>

Function Set-InternetProxy
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[String[]]$Proxy,
[Parameter(Mandatory=$False,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[AllowEmptyString()]
[String[]]$acs
)

Begin
{
$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
}

Process
{
Set-ItemProperty -path $regKey ProxyEnable -value 1
Set-ItemProperty -path $regKey ProxyServer -value $proxy
if($acs)
{
Set-ItemProperty -path $regKey AutoConfigURL -Value $acs
}
}

End
{
Write-Output "Proxy is now enabled"
Write-Output "Proxy Server : $proxy"
if ($acs)
{
Write-Output "Automatic Configuration Script : $acs"
}
else
{
Write-Output "Automatic Configuration Script : Not Defined"
}
}
}

将上面的代码复制下来并保存为Set-InternetProxy.ps1即可。

结语

有些同学可能使用的是 Git 的客户端,比如我现在正在使用的 Github Desktop ,里面可能并没有代理设置的选项,不过别着急,这些客户端一般在底层都是调用的命令行工具,所以同样按照上述步骤进行设置即可。并在如下图选择你要使用的命令行工具

avatar

最后看到 clone 的速度从10Kib/s变成了1Mib/s,是不是开心极了 :)

参考资料

1、fazero

2、Microsoft脚本中心

Hello World

发表于 2018-02-08 | 更新于 2019-02-03 | 分类于 生活随笔

欢迎光临

  • 欢迎来到WHY的个人博客,今天是二〇一八年二月八日,农历二〇一七年腊月廿三,恰逢新春佳节。经过了博主长达半个多月的学习和准备,我的博客终于上线了。

关于博主

  • 某四非一本大学计算机科学与技术专业在读,未来的苦逼码农。

  • 本人 微博、知乎、Facebook、Twitter、Google+ 欢迎关注或私信交流。

  • 本人邮箱:66why99@gamil.com

  • 生乎吾前,其闻道也固先乎吾,吾从而师之;生乎吾后,其闻道也亦先乎吾,吾从而师之。

                                    ——韩愈《师说》

浏览须知

  • 在您浏览、转载本网站文章时,意味着您悉知并遵守知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议,否则请停止浏览或转载本网站的一切内容。

感谢

本博客的建成感谢以下个人、公司、团体、组织(排名不分先后):

1
2
3
4
5
6
感谢GitHub(1)为本博客提供托管服务。
感谢七牛云(2)为本博客提供图片存储空间。
感谢ITGOYO技术站(3)为博主提供建站指南。
感谢indigo(4.1)、Yilia(4.2)、现主题NexT(4.3)为本博客提供主题。
感谢hexo(5)为本博客提供博客框架。
感谢光临本博客的人,你们的到来让这里蓬荜生辉。

注:

  • (1)Github
  • (2)七牛云
  • (3)ITGOYO技术站
  • (4)
    • (4.1)indigo
    • (4.2)Yilia
    • (4.3)NexT
  • (5)hexo
WHY

WHY

胆小认生,不易相处。
年轻无为,卖码为生。

2 日志
2 分类
5 标签
RSS
GitHub E-Mail Weibo Google+ Twitter Facebook
Creative Commons
Links
  • 燕山大学
© 2017 – 2019 WHY
0%