挺好用的socks5库go-socks5
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 ,不然什么请求到服务器上绕一圈可是有点过了。。
挺好用的socks5库go-socks5的更多相关文章
- requests库使用socks5代理
备查: #!usr/bin/env python # coding=utf-8 import requests proxies = {'https': 'https://127.0.0.1:1080' ...
- socks5服务器编写经验总结
一.Socks5服务器实现设计 本Socks5服务器是之前做的一个项目中的一个小部分东西,该项目是一个可以实现多级转发代理网络通讯的项目,能够隐藏网络数据包的源IP地址和端口,能够为上网的用户提供安全 ...
- HTTP协议和SOCKS5协议
HTTP协议和SOCKS5协议 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们平时上网的时候基本上是离不开浏览器的,尤其是搜索资料的时候,那么这个浏览器是如何工作的呢?用的又是 ...
- 自己动手开发Socks5代理服务器
一.Socks5协议简介 socks5是基于传输层的协议,客户端和服务器经过两次握手协商之后服务端为客户端建立一条到目标服务器的通道,在传输层转发TCP/UDP流量. 关于socks5协议规范,到处都 ...
- SOCKS5的出现缓解了各种具体协议需要专门设计代理协议的困难局面
socks5_百度百科 https://baike.baidu.com/item/socks5/8915011?fr=aladdin 如果您的机器具有一个合法的 Internet IP 地址, 或者您 ...
- 转-linux下配置socks5代理
简介: 在Linux下有各种各样的代理程序可用,象最常用的Squid,是http/https代理,也能代理ftp请求,但它实际上 是个HTTP代理程序,不是ftp代理,但它能处理ftp代理请求,就象浏 ...
- 爬虫学习--Requests库详解 Day2
什么是Requests Requests是用python语言编写,基于urllib,采用Apache2 licensed开源协议的HTTP库,它比urllib更加方便,可以节约我们大量的工作,完全满足 ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- 一起学习Boost标准库--Boost.texical_cast&format库
今天接续介绍有关字符串表示相关的两个boost库: lexical_cast 将数值转换成字符串 format 字符串输出格式化 首先,介绍下lexical_cast ,闻其名,知其意.类似C中的at ...
随机推荐
- 在同一个服务器上同时配置xxxxxxxxxx1个tomcat
下面我们把配置的详细过程写在下面,以供参考:(此例以配置三个Tomcat为例) 下载apache-tomcat-7.0.63,下载下来的文件为apache-tomcat-7.0.63.zip. 解压该 ...
- php 推荐密码加密的方法
password_hash() 函数 password_hash() 函数用于创建密码的散列(hash) PASSWORD_DEFAULT - 使用 bcrypt 算法 (PHP 5.5.0 默认). ...
- Windows 挂起进程
A thread can suspend and resume the execution of another thread. While a thread is suspended, it is ...
- Ubuntu 18.04更换apt-get源
使用apt-get安装时,会很慢,更换了国内的源后,就可以解决这个问题了. 1. 备份sources.list文件 sudo cp /etc/apt/sources.list /etc/apt/sou ...
- java之 向上转型与向下转型
向上转型 class father { public void eat(){ System.out.println("father eat()"); } } class son e ...
- Unity(GameObject)
####1. 这个方法用于发送一个数据到指定的方法中,第三个参数是是否强制接收 以下三种方法发送消息的形式,各有不同的效果,可以通过第一个参数指定要发送的方法名名,第二个是发送的参数值,第三个参数是是 ...
- memcached 原子性操作 CAS模式
2019独角兽企业重金招聘Python工程师标准>>> 应用场景分析: 如原来MEMCACHED中的KES的内容为A,客户端C1和客户端C2都把A取了出来,C1往准备往其中加B,C2 ...
- SQL SERVER 性能优化二: 数据库初始值大小及增长方式设置
数据库增长方式主要有两种,按百分比自动增长和按固定大小自动增长,设置初始大小和增长方式需谨慎. 初始大小就是建库的大小,设小了,容易造成磁盘碎片,频繁增长也会影响IO响应.设大了,也不行,设大了,每次 ...
- MySQL数据库的套接字文件和pid文件
MySQL数据库的套接字文件和pid文件 socket文件:当用Unix域套接字方式进行连接时需要的文件. pid文件:MySQL实例的进程ID文件. MySQL表结构文件:用来存放MySQL表结构定 ...
- CodeForces-259B]Little Elephant and Magic Square
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains ...