帮朋友刷网络投票,由于刷投票最大的问题在ip上,家里用的是光猫,所以针对自己家里的这款光猫写了定时刷票功能,写完后拿出来共享。
package vote;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.ArrayList;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.Header;
public class SendPostMethod {
public String methodPost(String url,NameValuePair[] data){
String response= "";//要返回的response信息
HttpClient httpClient = new HttpClient();
List<Header> headers = new ArrayList<Header>();
headers.add(new Header("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon;)"));
//qq投票判断referer,不然投票无效
headers.add(new Header("referer", "http://xxx.qq.com/zt2011/matchofgym/index.htm"));
httpClient.getHostConfiguration().getParams().setParameter(
"http.default-headers", headers);
PostMethod postMethod = new PostMethod(url);
// 将表单的值放入postMethod中
postMethod.setRequestBody(data);
// 执行postMethod
int statusCode = 0;
try {
statusCode = httpClient.executeMethod(postMethod);
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发
// 301或者302
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY
|| statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
// 从头中取出转向的地址
Header locationHeader = postMethod.getResponseHeader("location");
String location = null;
if (locationHeader != null) {
location = locationHeader.getValue();
System.out.println("The page was redirected to:" + location);
response= methodPost(location,data);//用跳转后的页面重新请求。
} else {
System.err.println("Location field value is null.");
}
} else {
System.out.println(postMethod.getStatusLine());
try {
response= postMethod.getResponseBodyAsString();
} catch (IOException e) {
e.printStackTrace();
}
postMethod.releaseConnection();
}
return response;
}
public void sendVote(){
String url = "http://input.vote.qq.com/survey.php";
NameValuePair pjtId = new NameValuePair("PjtID", "1234567");
NameValuePair result = new NameValuePair("result", "0");
NameValuePair sbj =new NameValuePair("sbj_1234567[]", "123456");
NameValuePair[] data = {pjtId, result, sbj};
String response = methodPost(url,data);
System.out.println("sendVote********"+response);
}
public void loginInRouter() throws IOException{
String url = "http://192.168.1.1";
NameValuePair username = new NameValuePair("Username", "useradmin");
NameValuePair password = new NameValuePair("Password", "prdih");
//获得光猫的token,验证正确才能登录
NameValuePair token = new NameValuePair("Frm_Logintoken", Router.findLoginToken(url));
NameValuePair[] data = {username, password, token};
String response = methodPost(url, data);
System.out.println("loginInRouter********"+response);
}
public void resetRouter() throws IOException{
String url = "http://192.168.1.1/manager_dev_conf_t.gch";
NameValuePair action = new NameValuePair("IF_ACTION", "devrestart");
NameValuePair flag = new NameValuePair("flag", "1");
NameValuePair[] data = {action, flag};
String response = methodPost(url, data);
System.out.println("resetRouter********"+response);
}
public static void main(String[] args) throws IOException,UnsupportedEncodingException {
SendPostMethod sm = new SendPostMethod();
//sm.sendVote();
sm.loginInRouter();
sm.resetRouter();
}
}
这是模拟表单提交代码,是刷ip和投票功能的核心部分。
package vote;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import org.apache.commons.lang3.StringUtils;
public class Router {
private static final String regex = "\"\\d+\";";
public static String findLoginToken(String url) throws IOException{
Document doc = Jsoup.connect(url).get();
String content = doc.outerHtml();
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
String result = "";
if(m.find()){
result = m.group();
result = StringUtils.remove(result, "\"");
result = StringUtils.remove(result, ";");
}
return result;
}
public static void main(String[] args) throws IOException{
String routerAddress = "http://192.168.1.1";
String content = Router.findLoginToken(routerAddress);
System.out.println("token id: " + content + " .");
}
}
中兴F420的机器登录时需要token验证,所以一定要获得token才能通过登录。
以上代码有部分是直接拿网上的源码修改而成的,投票和定时重启光猫是自己写的,由于重启光猫和分配ip时间比较长,所以一般每3分钟才能投一次票,傍晚下班的时候可能需要4分钟一次,需要做出一定调整。包括定时器的源码都放在附件里供大家下载。
分享到:
相关推荐
NULL 博文链接:https://akunamotata.iteye.com/blog/1625804
中兴F420 V2.0光猫固件,H248,非常稀有的,赶快下载。
大家都知道,去年8月份F420版本升级后就被加密了,Telnet端口也被屏蔽了,各种破解方法都失效了,现在就教大家怎么用TTL连接开启F420被屏蔽的Telnet,TTL连接上后可用sendcmd命令修改限制连接数,关闭tr69远程,开启...
中兴F420光猫设备手工配置方法2.pdf
中兴光猫F420 5.0固件,
光猫(中兴F420F460F660)超级密码,开无线路由.doc
F420_V5.0.1P1T5_NAND128K_UPGRADE_BOOTLDR.bin
中兴F420破解步骤
破解F420及同系列光猫的telecomadmin密码以及破解4台电脑限制
中兴光猫ONU配置注册清零工具 一、应用背景 针对运营商定制PON ONU终端,比如定制E8-C,根据定制规范,所有终端都需要连 接ITMS网管平台,终端开通需要ITMS下发、激活业务配置后才能正常使用; 这期间ITMS下发失败...
中兴F420联通通用版配置文件201408,适用于天津电信的中兴F420设备,再加上AP就能省却路由器。换F460需要迁移配置和更改MAC
中兴 F420 V3.3 固件
中兴ZXA10 F420 EPON EL3 老版光纤猫升级固件 H248协议
中兴F420,F460,F660破解工具,可以用在中兴系列的无线猫和光纤猫上,中兴H108L,中兴F420,F460,F660等都可以用的上。
中兴 ZXA10_F420光网络终端-用户手册 ZXA10_F420光网络终端-用户手册 ZXA10_F420光网络终端-用户手册
现在有的中兴光纤都支持破解,支持在线破解超级密码登陆密码:1314520
中兴F420数据配置 1、OLT定义语音模板 conf t --进入配置模式 epon --进入EPON模式定义语音模板 voip-ip profile 3005_WG relation independent mode static gateway 10.70.216.1(要分配)dns 0.0.0.0 ----------...
主要介绍了光猫路由器(中兴和华为)切换路由模式与桥接模式的方法(图文详解)的相关资料,路由模式和桥接模式切换,发现一个不需要密码就可以切换的方法,现分享给大家,需要的朋友可以参考下
主要介绍了中兴(ZTE)光猫F420破解、桥接、加无线应用的方法详解的相关资料,破解光猫之后,大家就不需要买路由器了,也很好用,需要的朋友可以参考下
中兴F620通用固件,V3.30.20P5T3版。