连接需要验证的 socks5,当切换用户的时候并不会重新连接

2017-03-20 11:16:03 +08:00
 fuxkcsdn

如下代码

<?php

$ch = curl_init('httpbin.org/ip');

curl_setopt($ch, CURLOPT_PROXY, 'socks5://user1:passwd@127.0.0.1:1080');
curl_exec($ch);

curl_setopt($ch, CURLOPT_PROXY, 'socks5://another_user:passwd@127.0.0.1:1080'); // 切换用户
curl_exec($ch);

在 socks5 服务器中,只看得到第一次连接时的用户验证信息,第二次连接没有验证过程

1267 次点击
所在节点    分享发现
4 条回复
pubby
2017-03-20 11:25:00 +08:00
httpbin.org/ip keepalive 了吧,这样第二个请求根本不用走代理
fuxkcsdn
2017-03-20 19:04:33 +08:00
@pubby 确实是 keep alive 了,但它还是走代理的,只是复用了链接而不重新发起 socks5 验证
```shell
* Found bundle for host httpbin.org: 0x55ab9a6ec800
* Re-using existing connection! (#0) with host 127.0.0.1
* Connected to 127.0.0.1 (127.0.0.1) port 1080 (#0)
```

详细日志
```shell
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Hostname was NOT found in DNS cache
* 54
* 235
* 212
* 238
* Connected to 127.0.0.1 (127.0.0.1) port 1080 (#0)
> GET /ip HTTP/1.1
Host: httpbin.org
User-Agent: GuzzleHttp/6.2.1 curl/7.38.0 PHP/7.0.16-1~dotdeb+8.1

< HTTP/1.1 200 OK
< Connection: keep-alive
* Server gunicorn/19.7.0 is not blacklisted
< Server: gunicorn/19.7.0
< Date: Mon, 20 Mar 2017 11:00:08 GMT
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Content-Length: 30
< Via: 1.1 vegur
<
* Connection #0 to host httpbin.org left intact
{
"origin": "xx.xx.xx.xx"
}
* Found bundle for host httpbin.org: 0x55ab9a6ec800
* Re-using existing connection! (#0) with host 127.0.0.1
* Connected to 127.0.0.1 (127.0.0.1) port 1080 (#0)
> GET /ip HTTP/1.1
Host: httpbin.org
User-Agent: GuzzleHttp/6.2.1 curl/7.38.0 PHP/7.0.16-1~dotdeb+8.1

< HTTP/1.1 200 OK
< Connection: keep-alive
* Server gunicorn/19.7.0 is not blacklisted
< Server: gunicorn/19.7.0
< Date: Mon, 20 Mar 2017 11:00:13 GMT
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Content-Length: 30
< Via: 1.1 vegur
<
* Connection #0 to host httpbin.org left intact
{
"origin": "xx.xx.xx.xx"
}
```
pubby
2017-03-21 01:28:42 +08:00
Socks5 协议里,每次连接才会认证用户,既然是连接复用,没有从新连接,只是在原来的连接上继续收发数据(HTTP 1.1 keepalive 的行为)。
你可以指定请求头部 Connection: close 来禁止 keepalive 试试
fuxkcsdn
2017-03-21 11:46:13 +08:00
@pubby 刚测试指定 Connection: close ,确实可以禁止复用连接

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/348764

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX