若能避开猛烈的欢喜,自然也不会有悲痛的来袭。

动态切换代理IP,最低10s/次 - tor+socks+privoxy实现全球上万节点随机跳转

一、前言

之前有过类似场景需求,研究了下如何将socks(ss/ssr) + privoxy + tor 配合起来,实现可控时间变换代理IP,同时配合二级甚至多级代理,做到更好的隐匿性访问,代理原理如下:

torsocks转发过来的请求经过加密,然后自己再监听一个端口对外提供服务,privoxy则负责引用该端口,将socks代理转发为http/https代理,并且具备网页内容、管理Cookie、控制访问、去广告等功能,但本文重点在于如何将三方配合实现自定义时间内切换节点IP。

所以大前提是你的系统已经存在socks代理,如ss/ssr等,没有的话请先移步至这篇文章,同理不支持代理icmp,需要具备代理icmp硬性需求,更推荐你用ipsec等vpn软件实现。

二、特性与建议

  • 最小支持10s切换一次IP。

  • 全球tor节点随机跳转(截止到2021年2月底有7000+节点,参考tor官网: https://metrics.torproject.org/relayflags.html

  • 因为全球节点随机跳转,物理链路无法控制,如果跳转到较偏远地区,速度也会相对偏慢,因此你能做的就是保证你的socks代理速度优秀即可。

  • 使用代理执行某些需要长时间才能完成的操作,可适当将切换时间调大(如nmap、openvas等安全扫描场景)。

  • 仅供学习研究之用,请勿用于非法用途,使用本功能带来的相关法律责任本站概不负责,用户自行承担相关法律责任。

三、开始部署

sockstorprivoxy如何安装本文不再赘述,安装个软件都不会你还能干点啥,我甚至不觉得你会有类似需求。

要注意的是,tor不需要安装GUI浏览器界面,安装tor本身即可(xxx install tor)。

此项目我已经开源放到了github: https://github.com/RokasUrbelis/activeproxy,如果对你有帮助,希望不要吝啬手中的star,同时也期望你能提交pull requests,让这个项目更加强大!

1)克隆到本地

$ git clone https://github.com/RokasUrbelis/activeproxy

2)执行start.sh

此脚本写成交互式,包含启动、停止、获取实时IP:

$ bash start.sh  
1.start service
2.getip
3.stop service
4.exit

shell>1 #输入1回车即可
Plese input socks(shadowsocks or others) listening port(Default 1080):1081   #输入你socks监听的端口,默认1080
Listening Port=1081                       [ OK ]

How many seconds to change the IP(min=10,Defalut=10):600   #输入切换IP的间隔时间,默认10s,最低10s
Switch IP every 6000 seconds              [ OK ]
[info 02-28 12:19:12] Tor is starting     [ OK ]
[info 02-28 12:19:13] Privoxy is starting [ OK ]
Bye~
$ ps -ef|egrep 'tor|privoxy'    #查看进程是否正常运行
root     24833     1  0 12:31 pts/0    00:00:00 tor
root     24837     1  0 12:31 ?        00:00:00 privoxy /etc/privoxy/config
root     24939 19200  0 12:33 pts/0    00:00:00 grep -E tor|privoxy
$

同时提供了python支持(python3),shell和python选用其一即可,不需要重复执行

$ python3 start.py
How many seconds to change the IP(min=10,default=60):60
[Info:2021-02-28 12:31:44] privoxy is starting [OK]
[Info:2021-02-28 12:31:44] tor is starting [OK]
$

3)执行comon.sh

此脚本用于设置http代理,通过privoxy出去:

$ source comon.sh

到此部署已经完毕。

4)取消代理

$ bash start.sh
1.start service
2.getip
3.stop service
4.exit

shell>3           #键入3停止服务
STOP SERVICE                              [ OK ]
Bye~
$ souce unset.sh  #取消http代理

四、实时获取IP及验证

comon.sh里面写了一个getip函数,在你执行source comon.sh后,执行getip即可实时看到你当前代理IP,运行截图:

同时,以下几个命令也能实时获取你的外网IP:

$ curl ident.me
$ curl vip.linux-code.com
$ curl ifconfig.co
赞(20) 打赏
转载请注明出处:RokasYang's Blog » 动态切换代理IP,最低10s/次 -

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫