这几天折腾了一下关于Mac下的应用代理,写下这篇blog用来总结。
由于一些原因,国内访问国外一些网站有问题,有些应用提供了代理的设置,但是大多数是没有的。所以我们需要一些工具,使之可以正常使用。
###前提工具准备
1.在Mac下有一个方便的下载安装工具,类似于Ubuntu的apt-get 叫做Brew,下载方式他的官网有很详细的介绍。
2.一台提供sock代理的服务器
###安装tsocks 一般我们使用brew进行安装时,brew install+应用名。但是由于brew于一些三方作者的关系,我们需要手动创建formual。这里是原因
首先
vi /usr/local/Library/Formula/tsocks.rb
内容如下
require 'formula'
class Tsocks < Formula
# The original is http://tsocks.sourceforge.net/
# This GitHub repo is a maintained fork with OSX support
homepage 'http://github.com/pc/tsocks'
head 'https://github.com/pc/tsocks.git'
depends_on 'autoconf' => :build if MacOS.xcode_version.to_f >= 4.3
def install
system "autoconf", "-v"
system "./configure", "--prefix=#{prefix}", "--disable-debug", "--disable-dependency-tracking", "--with-conf=#{config_file}"
inreplace("tsocks") { |bin| bin.change_make_var! "LIBDIR", lib }
system "make"
system "make install"
etc.install "tsocks.conf.simple.example" => "tsocks.conf" unless config_file.exist?
end
def test
puts 'Your current public ip is:'
ohai `curl -sS ifconfig.me 2>&1`.chomp
puts "If your correctly configured #{config_file}, this should show the ip you have trough the proxy"
puts 'Your ip through the proxy is:'
ohai `tsocks curl -sS ifconfig.me 2>&1`.chomp
end
def config_file
etc / 'tsocks.conf'
end
end
之后输入
brew install --HEAD tsocks
下载安装可能需要等待很久,需要耐心等待下。
如果安装的时候提示 configure:error:cannot run C compiled programs
尝试使用
xcode-select --install
一切顺利我们就开始使用啦。
vi /usr/local/etc/tsocks.conf
###配置tsocks
server = proxy.xxx.com #your proxy domain or IP address
server_type = 5 #to use socks V5
server_port = 1080 #the port of your porxy
添加到配置中,查看是否生效
tsocks wget www.google.com
如果走的是sock5服务器,那么说明tsocks已经生效了,我们可以使用
tsocks open -a 'Safari'
打开任何应用,或者:
tsocks git push
使用命令行。enjoy it!