|
@@ -8,6 +8,8 @@ import org.openqa.selenium.firefox.FirefoxOptions;
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @ProjectName: autoConnectNetwork
|
|
* @ProjectName: autoConnectNetwork
|
|
@@ -29,6 +31,8 @@ public class Main {
|
|
String firefoxPath = args[3];
|
|
String firefoxPath = args[3];
|
|
System.setProperty("webdriver.gecko.driver",gecko);
|
|
System.setProperty("webdriver.gecko.driver",gecko);
|
|
while (true){
|
|
while (true){
|
|
|
|
+ System.out.println("判断网络是否连接");
|
|
|
|
+ System.out.println(LocalDateTime.now(ZoneId.systemDefault()));
|
|
if (!connected()){
|
|
if (!connected()){
|
|
// 执行连接操作
|
|
// 执行连接操作
|
|
System.out.println("执行连接操作");
|
|
System.out.println("执行连接操作");
|
|
@@ -42,6 +46,7 @@ public class Main {
|
|
private static void connection(String username, String password,String firefoxPath) throws InterruptedException {
|
|
private static void connection(String username, String password,String firefoxPath) throws InterruptedException {
|
|
FirefoxDriver firefoxDriver = null;
|
|
FirefoxDriver firefoxDriver = null;
|
|
try {
|
|
try {
|
|
|
|
+ System.out.println("注册驱动");
|
|
firefoxDriver = fireFoxDriverInit(firefoxPath);
|
|
firefoxDriver = fireFoxDriverInit(firefoxPath);
|
|
//打开网页
|
|
//打开网页
|
|
firefoxDriver.get("http://10.30.252.71/eportal/index.jsp?nasip=cc5b64e516a1fa61d915e184b913e171");
|
|
firefoxDriver.get("http://10.30.252.71/eportal/index.jsp?nasip=cc5b64e516a1fa61d915e184b913e171");
|
|
@@ -55,7 +60,7 @@ public class Main {
|
|
//选择登陆模式
|
|
//选择登陆模式
|
|
firefoxDriver.findElement(By.cssSelector("#selectDisname")).click();
|
|
firefoxDriver.findElement(By.cssSelector("#selectDisname")).click();
|
|
firefoxDriver.findElement(By.cssSelector("#_service_2")).click();
|
|
firefoxDriver.findElement(By.cssSelector("#_service_2")).click();
|
|
- Thread.sleep(20*1000);
|
|
|
|
|
|
+ Thread.sleep(1000);
|
|
//模拟点击登录
|
|
//模拟点击登录
|
|
firefoxDriver.findElement(By.cssSelector("#loginLink_div")).click();
|
|
firefoxDriver.findElement(By.cssSelector("#loginLink_div")).click();
|
|
} finally {
|
|
} finally {
|
|
@@ -63,6 +68,7 @@ public class Main {
|
|
if (firefoxDriver != null) {
|
|
if (firefoxDriver != null) {
|
|
firefoxDriver.quit();
|
|
firefoxDriver.quit();
|
|
}
|
|
}
|
|
|
|
+ System.out.println("释放资源");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -72,7 +78,7 @@ public class Main {
|
|
|
|
|
|
//设置参数
|
|
//设置参数
|
|
//开启无头模式
|
|
//开启无头模式
|
|
- //options.addArguments("--headless");
|
|
|
|
|
|
+ options.addArguments("--headless");
|
|
//设置窗口大小
|
|
//设置窗口大小
|
|
options.addArguments("--window-size=1920,1080");
|
|
options.addArguments("--window-size=1920,1080");
|
|
//设置允许所有远程连接
|
|
//设置允许所有远程连接
|
|
@@ -123,7 +129,7 @@ public class Main {
|
|
return false;
|
|
return false;
|
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(
|
|
BufferedReader bufferedReader = new BufferedReader(
|
|
- new InputStreamReader(process.getInputStream(), "UTF-8"));// windows下编码默认是GBK,Linux是UTF-8
|
|
|
|
|
|
+ new InputStreamReader(process.getInputStream(), "GBK"));// windows下编码默认是GBK,Linux是UTF-8
|
|
|
|
|
|
String line = null;
|
|
String line = null;
|
|
|
|
|
|
@@ -133,7 +139,7 @@ public class Main {
|
|
|
|
|
|
if (line.startsWith("bytes from",3))
|
|
if (line.startsWith("bytes from",3))
|
|
return true;
|
|
return true;
|
|
- if (line.startsWith("from"))
|
|
|
|
|
|
+ if (line.startsWith("来自"))
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|