Home php教程 php手册 PHP重启路由器以更换IP地址程序

PHP重启路由器以更换IP地址程序

May 25, 2016 pm 04:53 PM
router

本文章来给各位同学介绍一个关于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 = &#39;admin&#39;;
    $password = &#39;123456&#39;;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, &#39;http://192.168.0.1/userRpm/PPPoECfgRpm.htm?wantype=2&acc=65541234&psw=Hello123World&VnetPap=0&linktype=2&Disconnect=%B6%CF+%CF%DF&#39;);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_exec($ch);
    curl_close($ch);
}
?>
Copy after login

高亮处需要根据自己的情况修改,路由器地址有的是192.168.1.1,重启地址也各有不同,但大同小异,自己改改。

教程网址:

欢迎收藏∩_∩但请保留本文链接。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does router sys mean? What does router sys mean? Aug 23, 2022 am 10:42 AM

What does router sys mean?

Can the router be placed upside down? Can the router be placed upside down? Sep 22, 2023 pm 02:11 PM

Can the router be placed upside down?

What does router sn mean? What does router sn mean? Oct 27, 2022 pm 05:21 PM

What does router sn mean?

How many lights on the router are normal? 'Recommended detailed explanation of the normal status of the router indicator lights' How many lights on the router are normal? 'Recommended detailed explanation of the normal status of the router indicator lights' Feb 06, 2024 pm 09:12 PM

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? Why can't I access the Internet even though I'm connected to the router? Nov 24, 2023 pm 05:29 PM

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 are the benefits of turning on ipv6 on the router 'Advantages of using the latest IPv6' Feb 06, 2024 pm 05:34 PM

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? What is the impact of turning off dhcp on the router? Dec 01, 2023 pm 04:01 PM

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

Which one is faster, gateway or router? Which one is faster, gateway or router? Jun 19, 2023 pm 03:06 PM

Which one is faster, gateway or router?

See all articles