【小型系统】简单的刷票系统(突破IP限制进行投票)

简介: 相信大家平时肯定会收到朋友发来的链接,打开一看,哦,需要投票。投完票后弹出一个页面(恭喜您,您已经投票成功),再次点击的时候发现,啊哈,您的IP(***.***.***.***)已经投过票了,不能重复投票。这时候,我们可能会想,能不能突破ip地址的限制进行刷票呢?有了这样的想法,那就去做吧,下面我将介绍我这个简单的刷票系统,仅供有需求的园友们参考。

一、前言 

 

  相信大家平时肯定会收到朋友发来的链接,打开一看,哦,需要投票。投完票后弹出一个页面(恭喜您,您已经投票成功),再次点击的时候发现,啊哈,您的IP(***.***.***.***)已经投过票了,不能重复投票。这时候,我们可能会想,能不能突破ip地址的限制进行刷票呢?有了这样的想法,那就去做吧,下面我将介绍我这个简单的刷票系统,仅供有需求的园友们参考。


二、系统设计


  系统主要实现的是突破IP限制进行刷票,其中,由IP采集模块负责从互联网上爬取代理IP,放入阻塞队列,该任务会定期执行。之后由投票模块从阻塞队列中获取IP,并进行设置,然后进行投票。系统流程图如下:


image.png


三、系统技术


  系统使用HttpClient + JSoup + 多线程来完成刷票,HttpClient用于进行投票,JSoup用于解析页面,多线程技术用于分离任务,使得分工更加明确。使用到了生产者消费者模式,该模式直接使用BlockingQueue来实现。


四、系统介绍


  系统主要分为三个模块:


  ① IP采集模块


  ② 投票模块


  ③ IP信息模块


  其中,IP采集模块主要是从互联网爬取IP代理信息,并将该信息放入阻塞队列,这样就可以伪造IP,进行多次投票。


  其中,投票模块从IP采集模块放入阻塞队列取出IP信息,并设置代理,找到投票入口地址,然后进行投票操作。


  其中,IP信息模块主要是对爬取的IP信息进行了封装,方便其他模块进行操作。


  4.1 IP采集模块


  IP采集模块流程图如下



image.png

几点说明:


  1.系统使用的代理IP站点URL为http://www.kuaidaili.com/,www.xicidaili.com。


  2.提取IP信息为提取单条IP信息,并判断历史IP表是否已经存在,若存在,表示之前

已经加入过此IP信息,则直接丢弃,反之,则加入队列并加入历史IP表。


  3.此任务会定期开启,如一个小时爬取一次代理IP。


  4.2 投票模块


  投票模块流程图如下


image.png


几点说明:


  1.投票网站http://www.hnxdf.com/vote/,我们选取的第一位进行投票,分析出投票的入口为http://www.hnxdf.com/vote/iRadio_vote.asp?VoTeid=215。


  2.根据IP采集模块放入队列的IP信息进行设置,然后进行投票。


  4.3 IP信息模块


  此模块主要对从网站爬取的IP信息进行了封装,方便其他模块进行操作。

五、系统代码框架


  系统的整个代码框架如下


image.png


其中,bean包的IpInfo封装了爬取的IP信息。


  其中,entrance包的Vote为系统的入口。


  其中,thread包的IPCollectTask为爬取代理IP任务,VoteThread为进行投票线程。


六、系统代码


  1.IpInfo.java


package com.hust.grid.leesf.bean;
public class IpInfo {
    public IpInfo(String ipAddress, int port, String location,
            String anonymousType, String type, String confirmTime) {
        this(ipAddress, port, location, anonymousType, type, confirmTime, null,
                null);
    }
    public IpInfo(String ipAddress, int port, String location,
            String anonymousType, String type, String confirmTime,
            String getPostSupport, String responseSpeed) {
        this.ipAddress = ipAddress;
        this.port = port;
        this.location = location;
        this.anonymousType = anonymousType;
        this.type = type;
        this.confirmTime = confirmTime;
        this.getPostSupport = getPostSupport;
        this.responseSpeed = responseSpeed;
    }
    public String getIpAddress() {
        return ipAddress;
    }
    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }
    public int getPort() {
        return port;
    }
    public void setPort(int port) {
        this.port = port;
    }
    public String getLocation() {
        return location;
    }
    public void setLocation(String location) {
        this.location = location;
    }
    public String getAnonymousType() {
        return anonymousType;
    }
    public void setAnonymousType(String anonymousType) {
        this.anonymousType = anonymousType;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getConfirmTime() {
        return confirmTime;
    }
    public void setConfirmTime(String confirmTime) {
        this.confirmTime = confirmTime;
    }
    public String getGetPostSupport() {
        return getPostSupport;
    }
    public void setGetPostSupport(String getPostSupport) {
        this.getPostSupport = getPostSupport;
    }
    public String getResponseSpeed() {
        return responseSpeed;
    }
    public void setResponseSpeed(String responseSpeed) {
        this.responseSpeed = responseSpeed;
    }
    @Override
    public boolean equals(Object anthor) {
        if (this == anthor) {
            return true;
        }
        if (anthor == null || getClass() != anthor.getClass()) {
            return false;
        }
        IpInfo ipInfo = (IpInfo) anthor;
        return (this.ipAddress.equals(ipInfo.ipAddress)
                && this.port == ipInfo.port
                && this.location.equals(ipInfo.location)
                && this.anonymousType.equals(ipInfo.anonymousType)
                && this.type.equals(ipInfo.type) && this.confirmTime
                    .equals(ipInfo.confirmTime))
                && this.getPostSupport.equals(ipInfo.getPostSupport)
                && this.responseSpeed.equals(ipInfo.responseSpeed);
    }
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 89 * hash
                + (this.ipAddress != null ? this.ipAddress.hashCode() : 0);
        hash = 89 * hash + this.port;
        hash = 89 * hash
                + (this.location != null ? this.location.hashCode() : 0);
        hash = 89
                * hash
                + (this.anonymousType != null ? this.anonymousType.hashCode()
                        : 0);
        hash = 89 * hash + (this.type != null ? this.type.hashCode() : 0);
        hash = 89 * hash
                + (this.confirmTime != null ? this.confirmTime.hashCode() : 0);
        hash = 89
                * hash
                + (this.getPostSupport != null ? this.getPostSupport.hashCode()
                        : 0);
        hash = 89
                * hash
                + (this.responseSpeed != null ? this.responseSpeed.hashCode()
                        : 0);
        return hash;
    }
    @Override
    public String toString() {
        return "ipAddress = " + ipAddress + ", port = " + port + ", localtion = "
                + location + ", anonymousType = " + anonymousType + ", type = " 
                + type + ", confirmTime = " + confirmTime + ", getPostSupport = "
                + getPostSupport + ", responseSpeed = " + responseSpeed;
    } 
    private String ipAddress;
    private int port;
    private String location;
    private String anonymousType;
    private String type;
    private String confirmTime;
    private String getPostSupport;
    private String responseSpeed;
}


2.Vote.java


package com.hust.grid.leesf.entrance;
import java.util.Timer;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import com.hust.grid.leesf.bean.IpInfo;
import com.hust.grid.leesf.thread.IPCollectTask;
import com.hust.grid.leesf.thread.VoteThread;
public class Vote {
    private BlockingQueue<IpInfo> ipInfoQueue;
    private IPCollectTask ipCollectTask;
    private VoteThread voteThread;
    public Vote() {
        ipInfoQueue = new LinkedBlockingQueue<IpInfo>();
        ipCollectTask = new IPCollectTask(ipInfoQueue);
        voteThread = new VoteThread(ipInfoQueue);
    }
    public void vote() {
        Timer timer = new Timer();
        long delay = 0;
        long period = 1000 * 60 * 60;
        // 每一个小时采集一次ip
        timer.scheduleAtFixedRate(ipCollectTask, delay, period);
        // 开启投票任务
        voteThread.start();
    }
    public static void main(String[] args) {
        Vote vote = new Vote();
        vote.vote();
    }
}


 3.IPCollectTask.java


package com.hust.grid.leesf.thread;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.hust.grid.leesf.bean.IpInfo;
public class IPCollectTask extends TimerTask {
    private BlockingQueue<IpInfo> ipInfoQueue; // 连接生产者与消费者的阻塞队列
    private List<IpInfo> historyIpLists; // 记录已经获取的ip信息
    public IPCollectTask(BlockingQueue<IpInfo> ipInfoQueue) {
        this.ipInfoQueue = ipInfoQueue;
        this.historyIpLists = new ArrayList<IpInfo>();
    }
    /**
     * 获取www.xicidaili.com的ip地址信息
     */
    public void getXiCiDaiLiIpLists() {
        String url = "http://www.xicidaili.com/";
        String host = "www.xicidaili.com";
        Document doc = getDocumentByUrl(url, host);
        // 解析页面的ip信息
        parseXiCiDaiLiIpLists(doc);
    }
    /**
     * 解析页面的ip信息
     * 
     * @param doc
     */
    public void parseXiCiDaiLiIpLists(Document doc) {
        Elements eleLists = doc.getElementsByTag("tbody");
        Element tbody = eleLists.get(0); // 获取tbody
        Elements trLists = tbody.children();
        Element ele = null;
        for (int i = 0; i < trLists.size(); i++) {
            if ((i % 22 == 0) || (i % 22 == 1)) { // 去掉不符合条件的项
                continue;
            }
            ele = trLists.get(i);
            Elements childrenList = ele.children();
            String ipAddress = childrenList.get(1).text();
            int port = Integer.parseInt(childrenList.get(2).text());
            String location = childrenList.get(3).text();
            String anonymousType = childrenList.get(4).text();
            String type = childrenList.get(5).text();
            String confirmTime = childrenList.get(6).text();
            IpInfo ipInfo = new IpInfo(ipAddress, port, location,
                    anonymousType, type, confirmTime);
            putIpInfo(ipInfo);
        }
    }
    /**
     * 将ip信息放入队列和历史记录中
     * 
     * @param ipInfo
     */
    private void putIpInfo(IpInfo ipInfo) {
        if (!historyIpLists.contains(ipInfo)) { // 若历史记录中不包含ip信息,则加入队列中
            // 加入到阻塞队列中,用作生产者
            try {
                ipInfoQueue.put(ipInfo);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // 加入历史记录中
            historyIpLists.add(ipInfo);
        }
    }
    /**
     * 根据网页Document解析出ip地址信息
     * 
     * @param doc
     */
    private void parseKuaiDaiLiIpLists(Document doc) {
        Elements eleLists = doc.getElementsByTag("tbody");
        Element tbody = eleLists.get(0); // 获取tbody
        Elements trLists = tbody.children(); // 获取十条ip记录
        for (Element tr : trLists) { // 遍历tr
            Elements tdElements = tr.children(); // tr中的td包含了具体的信息
            String ipAddress = tdElements.get(0).text();
            int port = Integer.parseInt(tdElements.get(1).text());
            String anonymousType = tdElements.get(2).text();
            String type = tdElements.get(3).text();
            String getPostSupport = tdElements.get(4).text();
            String location = tdElements.get(5).text();
            String responseSpeed = tdElements.get(6).text();
            String confirmTime = tdElements.get(7).text();
            IpInfo ipInfo = new IpInfo(ipAddress, port, location,
                    anonymousType, type, confirmTime, getPostSupport,
                    responseSpeed);
            putIpInfo(ipInfo);
        }
    }
    /**
     * 根据提供的url和host来获取页面信息
     * 
     * @param url
     * @param host
     * @return
     */
    private Document getDocumentByUrl(String url, String host) {
        Document doc = null;
        try {
            doc = Jsoup
                    .connect(url)
                    .header("User-Agent",
                            "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0")
                    .header("Host", host).timeout(5000).get();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return doc;
    }
    /**
     * 获取http://www.kuaidaili.com/free/的ip
     */
    private void getKuaiDaiLiFreeIpLists() {
        // 第一次访问,需解析总共多少页
        String baseUrl = "http://www.kuaidaili.com/free/inha/";
        String host = "www.kuaidaili.com";
        Document doc = getDocumentByUrl(baseUrl, host);
        // 解析ip信息
        parseKuaiDaiLiIpLists(doc);
        Element listNav = doc.getElementById("listnav");
        // 获取listnav下的li列表
        Elements liLists = listNav.children().get(0).children();
        // 获取含有多少页的子元素
        Element pageNumberEle = liLists.get(liLists.size() - 2);
        // 解析有多少页
        int pageNumber = Integer.parseInt(pageNumberEle.text());
        // 拼接成其他页的访问地址
        for (int index = 1; index <= pageNumber; index++) {
            baseUrl = baseUrl + index;
            doc = getDocumentByUrl(baseUrl, host);
            parseKuaiDaiLiIpLists(doc);
            // 休眠一秒
            fallSleep(1);
        }
    }
    /**
     * 获取www.kuaidaili.com/proxylist/的ip
     */
    private void getKuaiDaiLiIpLists() {
        int start = 1;
        String baseUrl = "http://www.kuaidaili.com/proxylist/";
        String host = "www.kuaidaili.com";
        while (start <= 10) { // 爬取10页
            String url = baseUrl + start + "/";
            Document doc = getDocumentByUrl(url, host);
            // 解析ip信息
            parseKuaiDaiLiIpLists(doc);
            start++;
            // 休眠一秒
            fallSleep(1);
        }
    }
    /**
     * 进行休眠
     */
    private void fallSleep(long seconds) {
        try {
            Thread.sleep(seconds * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void run() {
        // getKuaiDaiLiFreeIpLists();
        System.out.println("IPCollect task is running");
        getKuaiDaiLiIpLists();
        getXiCiDaiLiIpLists();
    }
    public BlockingQueue<IpInfo> getIpInfoQueue() {
        return ipInfoQueue;
    }
    public static void main(String[] args) {
        BlockingQueue<IpInfo> queue = new LinkedBlockingQueue<IpInfo>();
        IPCollectTask task = new IPCollectTask(queue);
        Thread thread = new Thread(task);
        thread.start();
        try {
            Thread.sleep(30 * 1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("queue size is " + queue.size());
        try {
            while (!queue.isEmpty()) {
                System.out.println(queue.take());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("historyList size is " + task.historyIpLists.size());
    }
}


  4.VoteThread.java



package com.hust.grid.leesf.thread;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import com.hust.grid.leesf.bean.IpInfo;
public class VoteThread extends Thread {
    private BlockingQueue<IpInfo> ipInfoQueue;
    public VoteThread(BlockingQueue<IpInfo> ipInfoQueue) {
        this.ipInfoQueue = ipInfoQueue;
    }
    @Override
    public void run() {
        HttpClient client = new DefaultHttpClient();
        HttpParams params = client.getParams();
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 15000);
        HttpResponse response = null;
        HttpGet get = null;
        HttpEntity entity = null;
        HttpHost proxy = null;
        while (true) {
            IpInfo ipInfo = null;
            try {
                ipInfo = ipInfoQueue.take();
            } catch (InterruptedException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            proxy = new HttpHost(ipInfo.getIpAddress(), ipInfo.getPort());
            client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
                    proxy);
            get = new HttpGet(
                    "http://www.hnxdf.com/vote/iRadio_vote.asp?VoTeid=215");
            get.addHeader("Host", "www.hnxdf.com");
            get.addHeader("User-Agent",
                    "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0");
            try {
                response = client.execute(get);
                entity = response.getEntity();
                byte[] bytes = EntityUtils.toByteArray(entity);
                // 对响应内容编码格式进行转化,统一成utf-8格式
                String temp = new String(bytes, "gbk");
                byte[] contentData = temp.getBytes("utf-8");
                System.out.println(new String(contentData));
                System.out.println("-----------------------------------");
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


七、系统总结


  此系统很简单,想清楚思路之后很快就能够写出代码,系统运行时,由于代理IP站点提供的免费IP质量不是太高,有效的IP地址还是很少,所有效果不是特别理想,此系统功能也很简单,但是各位园友可以在此基础上去发挥自己的想象力,定制属于自己的投票系统。


目录
相关文章
|
2月前
|
存储 人工智能 弹性计算
阿里云服务器新购、续费、升级活动:38元轻量,新购续费同价+优惠券补贴等热门活动介绍
2026年阿里云云服务器优惠政策趋于多元化、精准化与长期化:以38元轻量服务器、99元e实例、199元u1实例构成入门锚点,以"新购续费同价"消除长期成本不确定性,并以1至5年阶梯折扣(最低2.4折)鼓励深度承诺,叠加优惠券、达量返券、学生券等工具。成本优化关键不在抢最低价,而在读懂优惠边界与互斥规则,找到匹配自身节奏的最优组合。
|
3月前
|
分布式计算 运维 API
Databricks 实测 Spark 比 Flink 快 92%,流计算要变天了。
Databricks 3月2日发布测评:Spark Real-Time Mode(RTM)在实时特征计算(编码、enrichment、聚合)中,较Flink最高快92%(p99延迟9ms vs 95ms)。RTM打破微批限制,实现毫秒级低延迟、全状态支持与流式Shuffle,挑战“必须双引擎”行业共识。
309 2
|
4月前
|
人工智能 缓存 自然语言处理
阿里云百炼模型订阅怎么选?Token Plan、Coding Plan与Night Plan节省计划对比指南
阿里云百炼作为一站式大模型服务平台,提供了丰富的订阅计划与模型服务,覆盖个人开发、团队协作、企业级应用等全场景。从面向个人开发者的Coding Plan,到团队协同的Token Plan,再到夜间特惠的Night Plan与成本优化的AI通用节省计划,不同计划在计费模式、模型支持、使用限制上差异显著。本文将系统拆解百炼四大核心订阅计划,详解Qwen系列模型能力差异,提供完整API接入代码与配置流程,并给出不同场景下的选型与省钱策略,帮助开发者与企业高效、低成本使用大模型服务。
593 1
|
4月前
|
人工智能 安全 Cloud Native
云上大模型安全围栏设计:链路、能力与 POC 指标
云上大模型应用的安全围栏,通常需要覆盖输入检测、输出复检、策略处置、日志审计、样本回流和合规治理。评估这类方案时,不建议只看厂商介绍或功能清单,更应关注它与模型服务、业务系统、日志平台、权限体系和安全运营流程的集成方式。本文以工程落地为主线,梳理大模型安全围栏的常见架构、方案类型和 POC 指标。
|
12月前
|
存储 人工智能 运维
AI重构知识管理:如何破解技术团队的6大效率困局
通过AI全链路赋能,实现技术文档智能生成、语义检索、隐性知识沉淀与企业级安全管控,破解研发中API文档低效、故障排查慢、知识复用难等痛点,提升文档效率300%、故障修复提速80%,助力团队从“被动管理”迈向“智能协同”,重构高效能研发新范式。
500 12
|
6月前
|
人工智能 自然语言处理 数据库
智能分诊+AI问诊+电子处方,互联网医院系统源码功能开发技术架构揭秘
本文从软件开发与系统架构视角,深入解析互联网医院系统源码的核心设计逻辑,重点拆解智能分诊、AI问诊与电子处方三大核心模块,并结合微服务架构、高并发设计、医疗数据安全与AI大模型接入等关键技术。
|
5月前
|
人工智能 Java C++
微服务网关怎么选:Spring Cloud Gateway vs Higress
微服务网关是系统统一入口,聚焦鉴权、限流、路由等横切关注点。本文对比Spring Cloud Gateway(Java生态、易上手、业务逻辑灵活)与Higress(C++/Envoy内核、高性能、云原生+AI原生、控制台驱动),从性能、运维、扩展性等9维度给出选型指南,助团队按场景精准决策
472 0
|
人工智能 运维 数据可视化
AR巡检轨道交通、地铁运维场景的应用技术方案|阿法龙XR云平台
基于AR眼镜与云端协同架构,融合YOLOv8算法与高精度数字孪生,实现地铁车辆智能巡检。支持可视化标记、自动缺陷识别、离线巡检同步及多维数据分析,覆盖计划制定、执行记录到报表输出全流程闭环管理,提升巡检效率与准确性。
|
人工智能 运维 数据可视化
申报开启丨2025年10月批次阿里云协同育人项目申报指南,支持所有学科
阿里云联合教育部启动2025年产学合作协同育人项目,面向本科高校征集教学改革、实践基地建设与师资培训项目,聚焦AI+X课程、AIGC设计、智能编码、大数据分析等方向,提供资金、技术与资源支持,深化产教融合,共育创新人才。申报截止11月30日。
|
8月前
|
SQL 人工智能 自然语言处理
业务持续变化时,语义层到底该怎么迭代才不会越改越乱?
业务持续变化时,语义层不能靠“打补丁”硬扛。关键在于构建可分层(对象/关系/属性/规则)、可回溯、可校验的迭代机制,实现映射、口径、对象、知识四类变更分离治理,并配套影响分析与持续校准闭环。