1.挺好用的socks5库

github.com/armon/go-socks5

2.示例代码

// Create a SOCKS5 server
conf := &socks5.Config{}
server, err := socks5.New(conf)
if err != nil {
panic(err)
} // Create SOCKS5 proxy on localhost port 8000
if err := server.ListenAndServe("tcp", "127.0.0.1:8000"); err != nil {
panic(err)
}

很简洁,当然正式用不能这么用,默认是没有认证的,也就是说所有人都能连你服务器。。

加认证也很简单

cred := StaticCredentials{
"foo": "bar",
} cator := UserPassAuthenticator{Credentials: cred} s, _ := New(&Config{AuthMethods: []Authenticator{cator}})

下面详细看一下这个认证

Config结构体:

// Config is used to setup and configure a Server
type Config struct {
// AuthMethods can be provided to implement custom authentication
// By default, "auth-less" mode is enabled.
// For password-based auth use UserPassAuthenticator.
AuthMethods []Authenticator // If provided, username/password authentication is enabled,
// by appending a UserPassAuthenticator to AuthMethods. If not provided,
// and AUthMethods is nil, then "auth-less" mode is enabled.
Credentials CredentialStore // Resolver can be provided to do custom name resolution.
// Defaults to DNSResolver if not provided.
Resolver NameResolver // Rules is provided to enable custom logic around permitting
// various commands. If not provided, PermitAll is used.
Rules RuleSet // Rewriter can be used to transparently rewrite addresses.
// This is invoked before the RuleSet is invoked.
// Defaults to NoRewrite.
Rewriter AddressRewriter // BindIP is used for bind or udp associate
BindIP net.IP // Logger can be used to provide a custom log target.
// Defaults to stdout.
Logger *log.Logger // Optional function for dialing out
Dial func(ctx context.Context, network, addr string) (net.Conn, error)
}

config结构体里面要传入AuthMethods

AuthMethods是一个Authenticator切片,Authenticator是个interface,

type Authenticator interface {
Authenticate(reader io.Reader, writer io.Writer) (*AuthContext, error)
GetCode() uint8
}

UserPassAuthenticator 实现了Authenticator

// UserPassAuthenticator is used to handle username/password based
// authentication
type UserPassAuthenticator struct {
Credentials CredentialStore
} func (a UserPassAuthenticator) GetCode() uint8 {
return UserPassAuth
}

最后转化为填充一个UserPassAuthenticator的Credentials ,

而Credentials 是一个map[string]string

type StaticCredentials map[string]string

最后要把Config里面的logger 字段给填了(这里略),就差不多能用了。

3. 适用场景

适用移动网络访问github慢的场景。不知道为啥移动上github总是很慢。在公司电信网络就很快,之前家里用联通的时候也没这个现象,我上github你限制我干吗。。用此socks配合浏览器插件foxyProxy绕过移动网络直连github效果明显。注意foxyProxy里面设置Patterns ,不然什么请求到服务器上绕一圈可是有点过了。。

最新文章

  1. 11.APP打包成ipa文件,然后利用Application Loader 上架
  2. Lambda表达式 和 Expression<T>
  3. 【Android】与服务器实现JSON数据通信
  4. Oracle数据库—— PL/SQL基础编程
  5. 「Windows MFC 」「Edit Control」 控件
  6. 《A First Course in Probability》-chaper8-极限定理-切比雪夫不等式
  7. hdu 1426 Sudoku Killer ( Dancing Link 精确覆盖 )
  8. 编写程序,从vector<char>初始化string
  9. Selenium WebDriver + python 自动化测试框架
  10. [C# 设计模式] Iterator - 迭代器模式:我与一份奥利奥早餐的故事
  11. Mybatis中输入输出映射和动态Sql
  12. canvas百分百特效
  13. Android 热修复方案Tinker(一) Application改造
  14. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A. Neverending competitions 水题
  15. Solr系列一:Solr(Solr介绍、Solr应用架构、Solr安装使用)
  16. apache启动不了, 查找错误
  17. 初试mininet(可选PyCharm)
  18. sqlserver之on与where条件
  19. MySQL启动很慢的原因
  20. nsq小试牛刀-0.3.0 API变更

热门文章

  1. Asp.Net Core 3.1 的启动过程5
  2. 【集群实战】Rsync常见错误总结
  3. HTML JavaScript 基础(下)
  4. 09-5.部署 EFK 插件
  5. 13、canvas操纵像素数据ImageData
  6. JavaWEB开发时FCKeditor类似office界面的ajax框架,加入后就能做界面类似office,能进行简单的文本编辑操作+配置手册...
  7. Tomcat的设置4——Tomcat的体系结构与设置基于端口号的虚拟主机
  8. 现代软件工程讲义 如何提出靠谱的项目建议 NABCD
  9. LeetCode 25. K 个一组翻转链表 | Python
  10. linux下编译boost的多线程程序