代理设置

滩主 · · 2199 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

终端代理设置

export {http,https,ftp}_proxy="http://user:pass@proxy:port/"
export https_proxy=$http_proxy HTTP_PROXY=$http_proxy HTTPS_PROXY=$http_proxy NO_PROXY=$no_proxy

wget设置代理

# wget代理配置
# 修改/etc/wgetrc或者~/.wgetrc
# 临时代理
wget -Y on -e "http_proxy=http://proxy:port" "www.wo.com.cn"

curl 设置代理

curl -x proxy:port www.wo.com.cn
 
# curl 使用sock5代理
# https://blog.emacsos.com/use-socks5-proxy-in-curl.html
curl --socks5-hostname 127.0.0.1:1086 www.google.com
curl --proxy socks5h://127.0.0.1:1086 www.google.com

git 设置代理

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
 
#只对github.com
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
#取消代理
git config --global --unset http.https://github.com.proxy)
 
git config --global --unset http.proxy
git config --global --unset https.proxy

ssh 代理

ssh -o ProxyCommand="nc -X 5 -x proxy.net:1080 %h %p" user@server.net
 
 
# ssh 代理配置
~/.ssh/config
Host *
    ProxyCommand nc -X 5 -x proxy.net:1080 %h %p
    
    
    
#使用SSH端口转发之后,TCP 端口 A 与 B 之间现在并不直接通讯,而是转发到了 SSH 客户端及服务端来通讯,从而自动实现了数据加密并同时绕过了防火墙的限制
ssh -g -f -N -L forwardingPort:targetIP:targetPort user@sshServerIP
ssh -f -N -R forwardingPort:targetIP:targetPort user@sshServerIP
 
ssh -NTL 9001:localhost:80 workspace
ssh -NTR 9001:localhost:8080 workspace



# 本地安装ss 实现workspace请求代理
# 本地执行
ssh -NTR 9001:localhost:1086 workspace
# ws上执行
curl --socks5-hostname 127.0.0.1:9001 www.google.com

nc命令

# https://linux.cn/article-9190-1.html
# nc连接
nc -v 127.0.0.1 8080
# nc监听
nc -l 8080
# nc做代理
nc -l 8080 | nc 192.168.1.200 80
# 代理  双向管道接受返回
mkfifo 2way
nc -l 8080 0<2way | nc 192.168.1.200 80 1>2way
nc -l 9001 0<2way | tee cap.log | nc 127.0.0.1 8888 1>2way

# 发送文件
nc -l  8080 > file.txt
nc 192.168.1.100 8080 --send-only < data.txt
# 端口转发
nc -u -l  80 -c  'nc -u -l 8080'
# 客户端关闭,服务端继续
nc -l -k 8080

printf "GET / HTTP/1.0\r\n\r\n" | nc 127.0.0.1 8080
printf "GET / HTTP/1.1\r\nHost: z\r\n\r\n" | nc 127.0.0.1 8080

网络工具

dig
nslookup

抓包工具
charles

Example

http代理端口5000,转发至5100
export http_proxy=127.0.0.1:5000
mkfifo 2way
nc -k -l 5000 0<2way | tee -a cap.log | nc 127.0.0.1 5100 1>2way
golang反向代理转发请求至5200
package main

import (
    "log"
    "net/http"
    "net/http/httputil"
    "net/url"
)

func init() {
    log.SetFlags(log.LstdFlags | log.Lshortfile)
}

type Proxy struct {
    p *httputil.ReverseProxy
}

func (p *Proxy) revert(w http.ResponseWriter, r *http.Request) {
    p.p.ServeHTTP(w, r)
}
`
`
func newReverseProxy(target *url.URL) *httputil.ReverseProxy {
    director := func(req *http.Request) {
        req.URL.Scheme = target.Scheme
        req.URL.Path = req.RequestURI
        req.URL.Host = target.Host
    }
    return &httputil.ReverseProxy{Director: director}
}

func main() {
    remote, _ := url.Parse("http://127.0.0.1:5200")
    proxy := newReverseProxy(remote)

    p := &Proxy{
        p: proxy,
    }
    http.HandleFunc("/", p.revert)

    err := http.ListenAndServe(":5100", nil)
    if err != nil {
        log.Println(err)
    }
}

5200转发请求至8888

mkfifo 2wayB
nc -k -l 5200 0<2wayB | tee -a cap.log | nc 127.0.0.1 8888 1>2wayB

charles抓包工具监听8888,负责最后的代理请求


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:滩主

查看原文:代理设置

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2199 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传