山东大学使用QLSC_STU避免掉线的方法java版实现

1、前言

学校的stu在使用的过程中,隔一段时间就会掉线需要重新登陆,尤其在使用它下载比较大的文件时,频繁掉线就非常讨厌了。下面的方法可帮你暂时解决这个问题,但不能保证以后也能,因为学校的stu有可能进行升级。

2、原理

在原理上参考了这篇文章点击打开链接,这篇文章使用python语言实现,本文使用java实现。

3、分步介绍(代码为简化版,介绍关键步骤)

3-1、public String sendPost(String url, String param) {// 发送post请求
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
............
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义按字节来读取URL的响应
ins = conn.getInputStream();
byte[] bytes = new byte[ins.available()];
ins.read(bytes);
result = new String(bytes, "GB2312");//此处读取的响应编码为GB2312

}

3-2、public InetAddress getAddress() {// 获取本机有效ip,格式为/211.87.23.214
for (Enumeration<NetworkInterface> interfaces = NetworkInterface// 获取本机的所有网络接口
.getNetworkInterfaces(); interfaces.hasMoreElements();) {
NetworkInterface networkInterface = interfaces.nextElement();// 遍历所有网络接口
if (networkInterface.isLoopback()// 是否为127.0.0.1
|| networkInterface.isVirtual()// 是否为虚拟机的网络
|| !networkInterface.isUp()) {// 是否启动该网络
continue;
}
Enumeration<InetAddress> addresses = networkInterface
.getInetAddresses();// 获取其ip
if (addresses.hasMoreElements()) {
return addresses.nextElement();
}
}
return null;
}

3-3、public Boolean ping(String ipaddress) {// 通过ping百度判断是否断网,如果百度倒闭了,就需要换网站了
Runtime runtime = Runtime.getRuntime();
String cmds = "ping " + ipaddress;
Process proc;
proc = runtime.exec(cmds);
proc.getOutputStream().close();
InputStream inputstream = proc.getInputStream();
InputStreamReader inputstreamreader = new InputStreamReader(
inputstream);
BufferedReader bufferedreader = new BufferedReader(
inputstreamreader);
String line;
while ((line = bufferedreader.readLine()) != null) {
if (line.contains("ms")) {//适合于中文WINDOWS系统
return true;
}
}
return false;
}

3-4、public void press() {// 按任意键继续
try {
System.in.read();
} catch (Exception e) {
}
}

4、源代码与jar包下载地址

源代码:点击打开链接

jar包:点击打开链接

5、使用方法:

先连接上stu,然后运行jar包(在命令行输入java -jar VisitStu.jar),不要关闭程序。


你可能感兴趣的:(山东大学使用QLSC_STU避免掉线的方法java版实现)