PHP重启路由器以更换IP地址程序
本文章来给各位同学介绍一个关于PHP重启路由器以更换IP地址程序,如果你对此有兴趣不防进入参考哦。
在采集大批量数据时常常会触发对方服务器的“自我保护”,请求过于频繁就限制访问。这时需要停留很长一段时间(十几分钟到几十分钟不等)才能恢复访问,这样采集数据的速度就受到非常大的限制。
解决方法有两个:
1 通过图片识别绕过验证码机制,告诉服务器:我不是蜘蛛,我是人。不信你瞧,我能看懂验证码。
2 更换IP,告诉服务器:我不是张三,我是李四。不信你瞧,我的IP地址和张三的不一样。
第一个方法难度稍高一点而且不靠谱,等哪天对方服务器升级了验证码了,这边也得跟进,麻烦多;而ISP(电信、联通、移动)那儿有很多IP,每次联网都会分配一个新的IP,因此方法二比较好。
以我的TP-LINK路由器为例,找到“网络参数”>“WAN口设置”,可以看到“自动连接”设置和“断线”按钮。每次点击“断线”按钮,就向ISP重新拨号,此时就换了一个IP。但大批量数据的采集需要的时间比较长,不可能总有人在旁边守着,最好能在PHP代码中,一旦发现被限制了就重启一次,这就回到本文的主题了:《通过PHP函数重启路由器以更换IP》
打开chrome浏览器的调试模式,然后点击“断线”按钮,看“Network”网络请求,可以看到实际执行的地址是:“http://192.168.0.1/userRpm/PPPoECfgRpm.htm?wantype=2&acc=65541234&psw=Hello123World&VnetPap=0&linktype=2&Disconnect=%B6%CF+%CF%DF”
然后模拟请求这个地址,经测试确实可以更换IP地址(通过http://api.akcms.com/myip.php可以看到当前IP)。接下来的就简单了:就用PHP使用Curl组件来实现这个请求的过程,我封装了一个函数resetip,具体代码如下:
<?php //本脚本测试重启路由器的WLAN连接 resetip(); function resetip() { $username = 'admin'; $password = '123456'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://192.168.0.1/userRpm/PPPoECfgRpm.htm?wantype=2&acc=65541234&psw=Hello123World&VnetPap=0&linktype=2&Disconnect=%B6%CF+%CF%DF'); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); curl_close($ch); } ?>
高亮处需要根据自己的情况修改,路由器地址有的是192.168.1.1,重启地址也各有不同,但大同小异,自己改改。
教程网址:
欢迎收藏∩_∩但请保留本文链接。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Can the router be placed upside down?

How many lights on the router are normal? 'Recommended detailed explanation of the normal status of the router indicator lights'

Why can't I access the Internet even though I'm connected to the router?

What are the benefits of turning on ipv6 on the router 'Advantages of using the latest IPv6'

What is the impact of turning off dhcp on the router?

Which one is faster, gateway or router?
