最近买了个nano Pi当作服务器,用来不间断的执行java程序,爬取超星网上未完成的作业并发送详情到qq邮箱中,省去了一个个翻看的繁琐操作.
因为学校会断电,网.若想让Nano Pi不需要人力干扰即可完成整个流程,就需要配置开机自启,且我们校园网需要登录,还应自动提交信息至校园网获取网络.
这篇文章仅仅只记录自动登录校园网部分
抓包并分析
登录的ip地址http://110.188.66.35:801/eportal/
“?c=Portal&a=login” //常量
+"&login_method=1"//常量
+ “&user_account=,1,账号”
+ “&user_password=密码”//
+ “&wlan_user_ip=”+ip//当前的ip
+ “&wlan_user_ipv6=”//常量
+ “&wlan_user_mac=000000000000”//常量
+ “&wlan_ac_ip=125.70.212.239”//常量
+ “&wlan_ac_name=PX-CDJCXY-XYWBRAS-01.MAN.M6000”//常量
+ “&jsVersion=3.1”);//常量
其中user_account=,1,账号 中的数字 1 很重要,描述用户的设备编号,我的校园网是可以以太网连接一个设备,wifi连接一个设备,每一个设备在电信的服务器都有一个编号,若你不小心填上了另一个要使用网络的编号,结果就是会将该设备踢下线,白给.比如我的电脑编号为0,而手机编号为1.若我让电脑自动登录,则将该值设为0;手机则反之.
这里因为我是想让nano pi连接以太网,电脑连接wifi,手机流量.
而这段代码最终会在nano pi上执行,所以设置为1,采用手机的id,应该也可以随便写,但具体每试验过
代码
因为代码最终会在linux上执行,所以采用linux的获取ip方法
见linux获取当前ip地址并发送至qq邮箱
获取windown系统的ip可以百度,
public static void main(String[] args) throws UnknownHostException, SocketException {
CloseableHttpClient httpclient = HttpClients.createDefault();
String ip = getlocalip();
System.out.println(ip);
HttpGet get = new HttpGet("http://110.188.66.35:801/eportal/?c=Portal&a=login" +
"&login_method=1"
+ "&user_account=,1,账号"
+ "&user_password=密码"
+ "&wlan_user_ip="+ip
+ "&wlan_user_ipv6="
+ "&wlan_user_mac=000000000000"
+ "&wlan_ac_ip=125.70.212.239"
+ "&wlan_ac_name=PX-CDJCXY-XYWBRAS-01.MAN.M6000"
+ "&jsVersion=3.1");
CloseableHttpResponse response;
try {
response = httpclient.execute(get);
String html = EntityUtils.toString(response.getEntity());
// System.out.print(html);
int start =html.indexOf(":");
String result =html.substring(start+2, start+3);
// System.out.println("result:"+result);
if(result.equals("0")) {
response = httpclient.execute(get);
html = EntityUtils.toString(response.getEntity());
System.out.print(html);
}
mail.sendmail("yjh1535@qq.com","nanoPI已联网IP地址为:"+ip);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}