挺好用的socks5库go-socks5
2024-09-07 12:29:06
1.挺好用的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 ,不然什么请求到服务器上绕一圈可是有点过了。。
最新文章
- 11.APP打包成ipa文件,然后利用Application Loader 上架
- Lambda表达式 和 Expression<;T>;
- 【Android】与服务器实现JSON数据通信
- Oracle数据库—— PL/SQL基础编程
- 「Windows MFC 」「Edit Control」 控件
- 《A First Course in Probability》-chaper8-极限定理-切比雪夫不等式
- hdu 1426 Sudoku Killer ( Dancing Link 精确覆盖 )
- 编写程序,从vector<;char>;初始化string
- Selenium WebDriver + python 自动化测试框架
- [C# 设计模式] Iterator - 迭代器模式:我与一份奥利奥早餐的故事
- Mybatis中输入输出映射和动态Sql
- canvas百分百特效
- Android 热修复方案Tinker(一) Application改造
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A. Neverending competitions 水题
- Solr系列一:Solr(Solr介绍、Solr应用架构、Solr安装使用)
- apache启动不了, 查找错误
- 初试mininet(可选PyCharm)
- sqlserver之on与where条件
- MySQL启动很慢的原因
- nsq小试牛刀-0.3.0 API变更
热门文章
- Asp.Net Core 3.1 的启动过程5
- 【集群实战】Rsync常见错误总结
- HTML JavaScript 基础(下)
- 09-5.部署 EFK 插件
- 13、canvas操纵像素数据ImageData
- JavaWEB开发时FCKeditor类似office界面的ajax框架,加入后就能做界面类似office,能进行简单的文本编辑操作+配置手册...
- Tomcat的设置4——Tomcat的体系结构与设置基于端口号的虚拟主机
- 现代软件工程讲义 如何提出靠谱的项目建议 NABCD
- LeetCode 25. K 个一组翻转链表 | Python
- linux下编译boost的多线程程序