首页

基于gargoylesoftware的htmlunit的WebClient实现获取腾达路由器动态公网IP地址

标签:gargoylesoftware,htmlunit,公网IP,网页爬虫,路由器,动态IP,HtmlPage,模拟浏览器     发布时间:2018-03-20   

一、前言

基于gargoylesoftware的htmlunit开源模拟浏览器运行器,模拟登录腾达路由器Tenda爬虫,从而实现获取公网动态IP地址,这样可以定时刷新获取到公网地址,从而可以实现了域名和动态IP的绑定。

二、示例代码

1. WebClientDemo分别模拟用户登录、点击查看系统状态

package com.xwood.craw.crawler.processor.tenda;@b@@b@import com.gargoylesoftware.htmlunit.BrowserVersion;@b@import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;@b@import com.gargoylesoftware.htmlunit.WebClient;@b@import com.gargoylesoftware.htmlunit.html.HtmlPage;@b@@b@public class WebClientDemo {@b@	@b@	public static  WebClient webClient=getWebClientInstance();@b@	@b@	private static WebClient getWebClientInstance() {@b@		WebClient webClient = new WebClient(BrowserVersion.CHROME);@b@		webClient.getOptions().setJavaScriptEnabled(true);@b@		webClient.getOptions().setActiveXNative(false);@b@		webClient.getOptions().setCssEnabled(false);@b@		webClient.getOptions().setThrowExceptionOnScriptError(false);@b@		webClient.waitForBackgroundJavaScript(8 * 1000);@b@		webClient.setAjaxController(new NicelyResynchronizingAjaxController());@b@		return webClient;@b@	}@b@@b@	public static void main(String[] args) throws  Exception {@b@		  //1.获取授权认证 -- 通过用户名密码模拟登录@b@		  HtmlPage loginAuthPage1 = webClient.getPage("http://192.168.1.1/login/Auth?username=admin&password=MTU5NDE4NTkzODc=");@b@		  //2.获取路由系统状态@b@		  HtmlPage sysInfoPage2 =webClient.getPage("http://192.168.1.1/goform/getSysInfo?0.9524443088282748&_=1521554986074");@b@		  //3.打印路由器系统信息@b@		  System.out.println(sysInfoPage2.asXml());@b@	}@b@@b@}

运行控台台输出结果如下

<?xml version="1.0" encoding="ISO-8859-1"?>@b@<html>@b@  <head/>@b@  <body>@b@    {"portLink":"1,1,1,1,0","sysInfo":{"sysInfoDevName":"企业级无线路由器","sysInfoRunTime":"119d4h5m34s",@b@    "sysInfoSysTime":"2018-03-20 23:49:49","sysInfoSoftVersion":"V15.11.0.6(752_816)",@b@    "cpuUsePercent":2,"memoryUsePercent":75},"lanInfo":{"lanIp":"192.168.1.1",@b@    "lanMac":"CC:2D:21:2A:1B:30"},"wanInfo":[{"wanStatus":"wired",@b@    "wanError":"authPass","wanType":"pppoe","wanIP":"125.174.212.148",@b@    "wanMask":"255.255.255.255","wanGateway":"125.174.212.1",@b@    "wanDns1":"10.64.0.200","wanDns2":"10.64.0.100","wanUpFlux":"0.40KB/s","wanDownFlux":"0.46KB/s"}]}@b@  </body>@b@</html>


<<热门下载>>