|
@@ -1,25 +1,48 @@
|
|
package space.anyi.autoConnectNetwork;
|
|
package space.anyi.autoConnectNetwork;
|
|
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
|
+import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.openqa.selenium.By;
|
|
import org.openqa.selenium.By;
|
|
import org.openqa.selenium.WebElement;
|
|
import org.openqa.selenium.WebElement;
|
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
|
|
|
+import space.anyi.autoConnectNetwork.entry.Student;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.InputStreamReader;
|
|
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
+import java.net.URL;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @ProjectName: autoConnectNetwork
|
|
* @ProjectName: autoConnectNetwork
|
|
* @FileName: Main
|
|
* @FileName: Main
|
|
* @Author: 杨逸
|
|
* @Author: 杨逸
|
|
* @Data:2024/5/28 8:38
|
|
* @Data:2024/5/28 8:38
|
|
- * @Description: TODO
|
|
|
|
|
|
+ * @Description:
|
|
*/
|
|
*/
|
|
public class Main {
|
|
public class Main {
|
|
|
|
+ private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
public static void main(String[] args) throws IOException, InterruptedException {
|
|
public static void main(String[] args) throws IOException, InterruptedException {
|
|
|
|
+ f2();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 模拟点击的方式连接校园网
|
|
|
|
+ * @param args
|
|
|
|
+ * @throws IOException
|
|
|
|
+ * @throws InterruptedException
|
|
|
|
+ * @description:
|
|
|
|
+ * @author: 杨逸
|
|
|
|
+ * @data:2024/10/16 12:56:21
|
|
|
|
+ * @since 1.0.0
|
|
|
|
+ */
|
|
|
|
+ public static void f1(String[] args) throws IOException, InterruptedException {
|
|
if (args.length!=4) {
|
|
if (args.length!=4) {
|
|
System.out.println("参数错误");
|
|
System.out.println("参数错误");
|
|
System.out.println("用户名,密码,firefoxDriver,firefoxPath未设置正确");
|
|
System.out.println("用户名,密码,firefoxDriver,firefoxPath未设置正确");
|
|
@@ -43,6 +66,167 @@ public class Main {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 调接口连接校园网
|
|
|
|
+ * @throws IOException
|
|
|
|
+ * @throws InterruptedException
|
|
|
|
+ * @description:
|
|
|
|
+ * @author: 杨逸
|
|
|
|
+ * @data:2024/10/16 13:18:22
|
|
|
|
+ * @since 1.0.0
|
|
|
|
+ */
|
|
|
|
+ public static void f2() throws IOException, InterruptedException {
|
|
|
|
+ //初始化校园网信息
|
|
|
|
+ List<Student> list = new ArrayList<>();
|
|
|
|
+ ImportParams importParams = new ImportParams();
|
|
|
|
+ importParams.setTitleRows(1);
|
|
|
|
+ importParams.setHeadRows(1);
|
|
|
|
+ list = ExcelImportUtil.importExcel(new File("账号密码.xlsx"), Student.class, importParams);
|
|
|
|
+ int mod = list.size(),index = 0;
|
|
|
|
+
|
|
|
|
+ while (true){
|
|
|
|
+ //判断网络是否连接
|
|
|
|
+ if (!connected()){
|
|
|
|
+ System.out.println("=======================");
|
|
|
|
+ System.out.println("无网络连接");
|
|
|
|
+ System.out.println("index = " + index);
|
|
|
|
+ //连接网络
|
|
|
|
+ Student student = list.get(index);
|
|
|
|
+ String userId = student.getSno().trim();
|
|
|
|
+ if(userId.charAt(0) == '\'')userId = userId.substring(1);
|
|
|
|
+ String password = student.getCardId().trim().substring(0,10);
|
|
|
|
+ if(password.charAt(0) == '\'')password = student.getCardId().trim().substring(1,11);
|
|
|
|
+ System.out.println("用户名:"+userId);
|
|
|
|
+ System.out.println("密码:"+password);
|
|
|
|
+ try {
|
|
|
|
+ //连接校园网
|
|
|
|
+ connection(userId,password);
|
|
|
|
+ }catch (IOException e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ System.err.println("检查网络连接是否已经连接到校园网的WiFi");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ index++;
|
|
|
|
+ index%=mod;
|
|
|
|
+ }
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void connection(String userId, String password) throws IOException {
|
|
|
|
+ String queryString= "nasip%3Dcc5b64e516a1fa61d915e184b913e171";
|
|
|
|
+ HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://10.30.252.71/eportal/index.jsp?nasip=cc5b64e516a1fa61d915e184b913e171").openConnection();
|
|
|
|
+ //打开首页获取cookie和session
|
|
|
|
+ String cookie;
|
|
|
|
+ {
|
|
|
|
+ httpURLConnection.setRequestMethod("GET");
|
|
|
|
+ httpURLConnection.connect();
|
|
|
|
+ //print(httpURLConnection.getInputStream());
|
|
|
|
+ System.out.println(httpURLConnection.getResponseCode());
|
|
|
|
+ Map<String, List<String>> headerFields = httpURLConnection.getHeaderFields();
|
|
|
|
+ cookie = headerFields.get("Set-Cookie").get(0);
|
|
|
|
+ System.out.println("cookie = " + cookie);
|
|
|
|
+ httpURLConnection.disconnect();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //登陆
|
|
|
|
+ String userIndex = "";
|
|
|
|
+ {
|
|
|
|
+ //电信
|
|
|
|
+ String service = "",passwordEncrypt = "false";
|
|
|
|
+ service = "DianXin";
|
|
|
|
+ httpURLConnection = (HttpURLConnection) new URL("http://10.30.252.71/eportal/InterFace.do?method=login").openConnection();
|
|
|
|
+ httpURLConnection.setRequestMethod("POST");
|
|
|
|
+ httpURLConnection.setRequestProperty("Cookie",cookie);
|
|
|
|
+ httpURLConnection.setDoOutput(true);
|
|
|
|
+
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder("").append("userId=").append(userId).append("&password=").append(password).append("&service=").append(service).append("&queryString=").append(queryString).append("&passwordEncrypt=").append(passwordEncrypt);
|
|
|
|
+ OutputStream outputStream = httpURLConnection.getOutputStream();
|
|
|
|
+ outputStream.write(stringBuilder.toString().getBytes(StandardCharsets.UTF_8));
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ outputStream.close();
|
|
|
|
+
|
|
|
|
+ httpURLConnection.connect();
|
|
|
|
+ System.out.println(httpURLConnection.getResponseCode());
|
|
|
|
+ String response = print(httpURLConnection.getInputStream());
|
|
|
|
+
|
|
|
|
+ String s = response.split(":")[1].split(",")[0];
|
|
|
|
+ userIndex = s.substring(1,s.length()-1);
|
|
|
|
+ System.out.println(userIndex);
|
|
|
|
+ httpURLConnection.disconnect();
|
|
|
|
+
|
|
|
|
+ Map map = objectMapper.readValue(response, Map.class);
|
|
|
|
+ String message = (String) map.get("message");
|
|
|
|
+ //if ("false::PWD_REGULAR_MODIFY_WEB".equals(message)){
|
|
|
|
+ // System.out.println("重置密码");
|
|
|
|
+ // return true;
|
|
|
|
+ //}
|
|
|
|
+ //联通
|
|
|
|
+ service = "LianTong";
|
|
|
|
+ if (userIndex.length()<4){
|
|
|
|
+ httpURLConnection = (HttpURLConnection) new URL("http://10.30.252.71/eportal/InterFace.do?method=login").openConnection();
|
|
|
|
+ httpURLConnection.setRequestMethod("POST");
|
|
|
|
+ httpURLConnection.setRequestProperty("Cookie",cookie);
|
|
|
|
+ httpURLConnection.setDoOutput(true);
|
|
|
|
+
|
|
|
|
+ stringBuilder = new StringBuilder("").append("userId=").append(userId).append("&password=").append(password).append("&service=").append(service).append("&queryString=").append(queryString).append("&passwordEncrypt=").append(passwordEncrypt);
|
|
|
|
+ outputStream = httpURLConnection.getOutputStream();
|
|
|
|
+ outputStream.write(stringBuilder.toString().getBytes(StandardCharsets.UTF_8));
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ outputStream.close();
|
|
|
|
+
|
|
|
|
+ httpURLConnection.connect();
|
|
|
|
+ System.out.println(httpURLConnection.getResponseCode());
|
|
|
|
+ response = print(httpURLConnection.getInputStream());
|
|
|
|
+ s = response.split(":")[1].split(",")[0];
|
|
|
|
+ userIndex = s.substring(1,s.length()-1);
|
|
|
|
+ System.out.println(userIndex);
|
|
|
|
+ httpURLConnection.disconnect();
|
|
|
|
+ map = objectMapper.readValue(response, Map.class);
|
|
|
|
+ message = (String) map.get("message");
|
|
|
|
+ //if ("false::PWD_REGULAR_MODIFY_WEB".equals(message)){
|
|
|
|
+ // System.out.println("重置密码");
|
|
|
|
+ // return true;
|
|
|
|
+ //}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (userIndex.length()<4)return ;
|
|
|
|
+ //获取用户信息
|
|
|
|
+ byte[] userIndexBytes = new String("userIndex=" + userIndex).getBytes();;
|
|
|
|
+ {
|
|
|
|
+ httpURLConnection = (HttpURLConnection) new URL("http://10.30.252.71/eportal/InterFace.do?method=getOnlineUserInfo").openConnection();
|
|
|
|
+ httpURLConnection.setRequestMethod("POST");
|
|
|
|
+ httpURLConnection.setRequestProperty("Cookie",cookie);
|
|
|
|
+ httpURLConnection.setDoOutput(true);
|
|
|
|
+
|
|
|
|
+ OutputStream outputStream = httpURLConnection.getOutputStream();
|
|
|
|
+ outputStream.write(userIndexBytes);
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ outputStream.close();
|
|
|
|
+
|
|
|
|
+ httpURLConnection.connect();
|
|
|
|
+ System.out.println(httpURLConnection.getResponseCode());
|
|
|
|
+ print(httpURLConnection.getInputStream());
|
|
|
|
+ httpURLConnection.disconnect();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 连接网络
|
|
|
|
+ * @param username
|
|
|
|
+ * @param password
|
|
|
|
+ * @param firefoxPath
|
|
|
|
+ * @throws InterruptedException
|
|
|
|
+ * @description:
|
|
|
|
+ * @author: 杨逸
|
|
|
|
+ * @data:2024/10/16 12:56:45
|
|
|
|
+ * @since 1.0.0
|
|
|
|
+ */
|
|
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 {
|
|
@@ -100,7 +284,7 @@ public class Main {
|
|
* @since 1.0.0
|
|
* @since 1.0.0
|
|
*/
|
|
*/
|
|
private static boolean connected() throws IOException {
|
|
private static boolean connected() throws IOException {
|
|
- return ping("baidu.com",5);
|
|
|
|
|
|
+ return ping("bing.com",5) || ping("baidu.com",5);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -114,14 +298,13 @@ public class Main {
|
|
* @data:2024/05/28 08:49:12
|
|
* @data:2024/05/28 08:49:12
|
|
* @since 1.0.0
|
|
* @since 1.0.0
|
|
*/
|
|
*/
|
|
- private static boolean ping(String target_name, int out_time)
|
|
|
|
- throws IOException {
|
|
|
|
|
|
+ private static boolean ping(String target_name, int out_time) throws IOException {
|
|
|
|
|
|
Runtime runtime = Runtime.getRuntime();
|
|
Runtime runtime = Runtime.getRuntime();
|
|
|
|
|
|
String ping_command = "ping " + target_name + " -w " + out_time;
|
|
String ping_command = "ping " + target_name + " -w " + out_time;
|
|
|
|
|
|
- System.out.println("命令格式:" + ping_command);
|
|
|
|
|
|
+ //System.out.println("命令格式:" + ping_command);
|
|
|
|
|
|
Process process = runtime.exec(ping_command);
|
|
Process process = runtime.exec(ping_command);
|
|
|
|
|
|
@@ -135,7 +318,7 @@ public class Main {
|
|
|
|
|
|
while (null != (line = bufferedReader.readLine())) {
|
|
while (null != (line = bufferedReader.readLine())) {
|
|
|
|
|
|
- System.out.println(line);
|
|
|
|
|
|
+ //System.out.println(line);
|
|
|
|
|
|
if (line.startsWith("bytes from",3))
|
|
if (line.startsWith("bytes from",3))
|
|
return true;
|
|
return true;
|
|
@@ -148,4 +331,24 @@ public class Main {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 打印输入流
|
|
|
|
+ * @param inputStream
|
|
|
|
+ * @return {@code String }
|
|
|
|
+ * @throws IOException
|
|
|
|
+ * @description:
|
|
|
|
+ * @author: 杨逸
|
|
|
|
+ * @data:2024/10/16 13:13:17
|
|
|
|
+ * @since 1.0.0
|
|
|
|
+ */
|
|
|
|
+ private static String print(InputStream inputStream) throws IOException {
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
+ while (bufferedReader.ready()) {
|
|
|
|
+ stringBuilder.append(bufferedReader.readLine());
|
|
|
|
+ }
|
|
|
|
+ System.out.println(stringBuilder.toString());
|
|
|
|
+ bufferedReader.close();
|
|
|
|
+ return stringBuilder.toString();
|
|
|
|
+ }
|
|
}
|
|
}
|