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 ,不然什么请求到服务器上绕一圈可是有点过了。。

挺好用的socks5库go-socks5的更多相关文章

  1. requests库使用socks5代理

    备查: #!usr/bin/env python # coding=utf-8 import requests proxies = {'https': 'https://127.0.0.1:1080' ...

  2. socks5服务器编写经验总结

    一.Socks5服务器实现设计 本Socks5服务器是之前做的一个项目中的一个小部分东西,该项目是一个可以实现多级转发代理网络通讯的项目,能够隐藏网络数据包的源IP地址和端口,能够为上网的用户提供安全 ...

  3. HTTP协议和SOCKS5协议

    HTTP协议和SOCKS5协议 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们平时上网的时候基本上是离不开浏览器的,尤其是搜索资料的时候,那么这个浏览器是如何工作的呢?用的又是 ...

  4. 自己动手开发Socks5代理服务器

    一.Socks5协议简介 socks5是基于传输层的协议,客户端和服务器经过两次握手协商之后服务端为客户端建立一条到目标服务器的通道,在传输层转发TCP/UDP流量. 关于socks5协议规范,到处都 ...

  5. SOCKS5的出现缓解了各种具体协议需要专门设计代理协议的困难局面

    socks5_百度百科 https://baike.baidu.com/item/socks5/8915011?fr=aladdin 如果您的机器具有一个合法的 Internet IP 地址, 或者您 ...

  6. 转-linux下配置socks5代理

    简介: 在Linux下有各种各样的代理程序可用,象最常用的Squid,是http/https代理,也能代理ftp请求,但它实际上 是个HTTP代理程序,不是ftp代理,但它能处理ftp代理请求,就象浏 ...

  7. 爬虫学习--Requests库详解 Day2

    什么是Requests Requests是用python语言编写,基于urllib,采用Apache2 licensed开源协议的HTTP库,它比urllib更加方便,可以节约我们大量的工作,完全满足 ...

  8. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  9. 一起学习Boost标准库--Boost.texical_cast&format库

    今天接续介绍有关字符串表示相关的两个boost库: lexical_cast 将数值转换成字符串 format 字符串输出格式化 首先,介绍下lexical_cast ,闻其名,知其意.类似C中的at ...

随机推荐

  1. Java 排序算法-冒泡排序及其优化

    Java 排序算法-冒泡排序及其优化 什么是冒泡排序 基本写法 优化后写法 终极版本 源码及测试 什么是冒泡排序 这里引用一下百度百科上的定义: 冒泡排序(Bubble Sort),是一种计算机科学领 ...

  2. Web前端三大主流框架是什么?Web前端前景与就业形势

    近十年以来,IT行业发展火热,衍生了很多新职业,例如UI设计师.开发工程师.软件测试工程师等等,在众多备受瞩目的新生职业中,Web前端工程师是其中的一员.那么Web前端三大主流框架是什么呢? 一.We ...

  3. 小白必看,Python 各种下划线都是啥意思_、_xx、xx_、__xx、__xx__、_classname_

    我们在定义一些变量或者方法的时候,常常会用到下划线,在 Python 中,下划线可是很有用处的哟,比如变量,有些是一个下划线开头的(_xx),有些是两个下划线开头的(__xx),有些是在名称的结尾添加 ...

  4. python爬虫-User-Agent的伪造

    某些网站会识别python爬虫程序并阻断,通过构造User_Agent可以抵抗某些反爬虫机制 用fake-useragent这个库就能很好的实现 pycharm中安装步骤 产生随机的User-Agen ...

  5. 详解封装源码包成RPM包

    源码编译安装是最常用安装软件方式,可是面对工作量巨大时候就需要我们的RPM包上场了,统一的模块,一键安装.在面对一定数量的服务器上,RPM就可以为我们节省大量的时间. RPM可以在网上下载,但是当我们 ...

  6. Vue-cli4脚手架搭建

    一:要安装Node.js:安装路径要默认安装(node-v12.16.2-x64.msi-长支持 二:要安装cnpm 1)说明:npm(node package manager)是nodejs的包管理 ...

  7. MaxCompute Studio提升UDF和MapReduce开发体验

    原文链接:http://click.aliyun.com/m/13990/ UDF全称User Defined Function,即用户自定义函数.MaxCompute提供了很多内建函数来满足用户的计 ...

  8. MongoDB学习(四):通过Java使用MongoDB

    环境配置 在Java项目中使用MongoDB,需要在项目中引入mongo.jar这个包.下载地址:下载 请尽量下载较新的版本,本文用的是2.10.1. 连接MongoDB public synchro ...

  9. 数学--数论--HDU 12151七夕节 Plus (因子和线性筛)

    Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...

  10. 洛谷 P1816 忠诚 ST函数

    题目描述 老管家是一个聪明能干的人.他为财主工作了整整10年,财主为了让自已账目更加清楚.要求管家每天记k次账,由于管家聪明能干,因而管家总是让财主十分满意.但是由于一些人的挑拨,财主还是对管家产生了 ...