副标题#e#
你是否经常有在终端下通过一些实用程序进行工作的需求呢,比如:Git 等。但是由于这些终端程序默认并不支持 Socks 5 代理或 HTTP 代理,在访问一些需要科学上网的网络服务时速度或许会非常的慢。
通常我们的解决方法就是使用环境变量 export ALL_PROXY=socks5://proxyAddress:port 或者 export http_proxy=http://proxyAddress:port 给所有终端程序配置一个全局代理,这样做虽然有效但并不是最佳解决方案。
今天就给大家介绍一款神器 graftcp,graftcp 可以把任何指定的终端程序的 TCP 连接重定向到 SOCKS5 或 HTTP 代理,并且不会影响其它的终端程序。是不是很好的解决了你的痛点呢?
简介
graftcp 可以把任何指定程序(应用程序、脚本、shell 等)的 TCP 连接重定向到 SOCKS5 或 HTTP 代理。
对比 tsocks、proxychains 或 proxychains-ng,graftcp 并不使用 LD_PRELOAD 技巧来劫持共享库的 connect()、getaddrinfo() 等系列函数达到重定向目的,这种方法只对使用动态链接编译的程序有效。
对于静态链接编译出来的程序,例如默认选项编译的 Go 程序,proxychains-ng 就无效了。graftcp 使用 ptrace(2) 系统调用跟踪或修改任意指定程序的 connect 信息,对任何程序都有效。工作原理后面将会解释。
项目地址:https://github.com/hmgle/graftcp
安装
graftcp 在 Linux 系统内运行。graftcp-local 使用 Go 编写, Go 环境是必需的。
$ git clone https://github.com/hmgle/graftcp.git
$ cd graftcp
$ make
make 执行完后,即可运行 graftcp-local/graftcp-local 和 ./graftcp。你也可以把它们都安装进系统:
$ sudo make install
之后 graftcp-local 会随着系统启动而自动运行。
用法参数
graftcp-local:
$ graftcp-local/graftcp-local -h
Usage of graftcp-local/graftcp-local:
-config string
Path to the configuration file
-http_proxy string
http proxy address, e.g.: 127.0.0.1:8080
-listen string
Listen address (default ":2233")
-logfile string
Write logs to file
-loglevel value
Log level (0-6) (default 1)
-pipepath string
Pipe path for graftcp to send address info (default "/tmp/graftcplocal.fifo")
-select_proxy_mode string
Set the mode for select a proxy [auto | random | only_http_proxy | only_socks5] (default "auto")
-service string
Control the system service: ["start" "stop" "restart" "install" "uninstall"]
-socks5 string
SOCKS5 address (default "127.0.0.1:1080")
-syslog
Send logs to the local system logger (Eventlog on Windows, syslog on Unix)
graftcp:
$ graftcp -h
Usage: graftcp [options] prog [prog-args]
Options:
-a --local-addr=<graftcp-local-IP-addr>
graftcp-local's IP address. Default: localhost
-p --local-port=<graftcp-local-port>
#p#副标题#e#
Which port is graftcp-local listening? Default: 2233
-f --local-fifo=<fifo-path>
Path of fifo to communicate with graftcp-local.
Default: /tmp/graftcplocal.fifo
-b --blackip-file=<black-ip-file-path>
#p#副标题#e##p#分页标题#e#
The IP in black-ip-file will connect direct
-w --whiteip-file=<white-ip-file-path>
Only redirect the connect that destination ip in the
white-ip-file to SOCKS5
-n --not-ignore-local
Connecting to local is not changed by default, this
option will redirect it to SOCKS5
-h --help
Display this help and exit