网站投票程序

news/2024/5/10 8:11:17/文章来源:https://blog.csdn.net/weixin_34007886/article/details/93223382

  早前几个朋友需要帮忙投票,而现在的投票网站都基本上有个限制:一个ip一天只能头一次票。从网络上搜索到破解方法有两种:1、使用拨号网络接入,每次拨号成功后会自动分配ip;2、固定ip接入,可以采用代理方式,欺骗投票程序。基于这个思路做了两个版本的程序,下载地址

  1、拨号网络接入。这个方式采用的思路,开启两个线程:第一个做一死循环,拨号,投票,断网;第二个线程轮询处理异常窗口。

  该方法使用win API。同时使用网络上前辈写的RAD类进行拨号。按窗口名称搜索窗体,并置当前窗体和向窗体发送按键的win API调用

 

ExpandedBlockStart.gif获取窗体句柄和发送按键声明
 1 using System.Runtime.InteropServices;
 2         [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
 3         private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
 4 
 5         [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
 6         private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
 7 
 8         [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
 9         private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
10 
11         [DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
12         private static extern void SetForegroundWindow(IntPtr hwnd);
13 

 

 

 

ExpandedBlockStart.gif查找窗体句柄和发送按键方法
1           IntPtr hwnd = FindWindow(null, windowName); //查找窗体的句柄
2 
3             if (hwnd != IntPtr.Zero)
4             {
5                 SetForegroundWindow(hwnd);//将该句柄设为当前活动窗口
6                 SendKeys.SendWait(key);
7 
8             }

 

参考: 键盘按键编码信息

 

 网络牛人的调用windows拨号类,具体出自谁手不记得了。

 

ExpandedBlockStart.gif调用windows拨号类
  1 
  2 using System;
  3 using System.Runtime.InteropServices;
  4 using System.Collections.Generic;
  5 using System.Text;
  6 
  7 
  8 namespace RAD
  9 {
 10 
 11     ///调用方法:
 12     ///RASDisplay ras = new RASDisplay();
 13     ///ras.Disconnect();//断开连接
 14     ///ras.Connect("ADSL");//重新拨号 
 15     public struct RASCONN
 16     {
 17         public int dwSize;
 18         public IntPtr hrasconn;
 19         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 257)]
 20         public string szEntryName;
 21         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)]
 22         public string szDeviceType;
 23         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 129)]
 24         public string szDeviceName;
 25     }
 26 
 27     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
 28     public struct RasStats
 29     {
 30         public int dwSize;
 31         public int dwBytesXmited;
 32         public int dwBytesRcved;
 33         public int dwFramesXmited;
 34         public int dwFramesRcved;
 35         public int dwCrcErr;
 36         public int dwTimeoutErr;
 37         public int dwAlignmentErr;
 38         public int dwHardwareOverrunErr;
 39         public int dwFramingErr;
 40         public int dwBufferOverrunErr;
 41         public int dwCompressionRatioIn;
 42         public int dwCompressionRatioOut;
 43         public int dwBps;
 44         public int dwConnectionDuration;
 45     }
 46 
 47     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
 48     public struct RasEntryName
 49     {
 50         public int dwSize;
 51         //[MarshalAs(UnmanagedType.ByValTStr,SizeConst=(int)RasFieldSizeConstants.RAS_MaxEntryName + 1)]
 52         public string szEntryName;
 53         //#if WINVER5
 54         //  public int dwFlags;
 55         //  [MarshalAs(UnmanagedType.ByValTStr,SizeConst=260+1)]
 56         //  public string szPhonebookPath;
 57         //#endif
 58     }
 59     public class RAS
 60     {
 61         [DllImport("Rasapi32.dll", EntryPoint = "RasEnumConnectionsA",
 62              SetLastError = true)]
 63 
 64         internal static extern int RasEnumConnections
 65             (
 66             ref RASCONN lprasconn, // buffer to receive connections data
 67             ref int lpcb, // size in bytes of buffer
 68             ref int lpcConnections // number of connections written to buffer
 69             );
 70 
 71 
 72         [DllImport("rasapi32.dll", CharSet = CharSet.Auto)]
 73         internal static extern uint RasGetConnectionStatistics(
 74             IntPtr hRasConn,       // handle to the connection
 75             [In, Out]RasStats lpStatistics  // buffer to receive statistics
 76             );
 77         [DllImport("rasapi32.dll", CharSet = CharSet.Auto)]
 78         public extern static uint RasHangUp(
 79             IntPtr hrasconn  // handle to the RAS connection to hang up
 80             );
 81 
 82         [DllImport("rasapi32.dll", CharSet = CharSet.Auto)]
 83         public extern static uint RasEnumEntries(
 84             string reserved,              // reserved, must be NULL
 85             string lpszPhonebook,         // pointer to full path and
 86             //  file name of phone-book file
 87             [In, Out]RasEntryName[] lprasentryname, // buffer to receive
 88             //  phone-book entries
 89             ref int lpcb,                  // size in bytes of buffer
 90             out int lpcEntries             // number of entries written
 91             //  to buffer
 92             );
 93 
 94         [DllImport("wininet.dll", CharSet = CharSet.Auto)]
 95         public extern static int InternetDial(
 96             IntPtr hwnd,
 97             [In]string lpszConnectoid,
 98             uint dwFlags,
 99             ref int lpdwConnection,
100             uint dwReserved
101             );
102 
103         public RAS()
104         {
105         }
106     }
107     public enum DEL_CACHE_TYPE //要删除的类型。
108     {
109         File,//表示internet临时文件
110         Cookie //表示Cookie
111     }
112 
113     public class RASDisplay
114     {
115         [DllImport("wininet.dll", CharSet = CharSet.Auto)]
116         public static extern bool DeleteUrlCacheEntry(
117             DEL_CACHE_TYPE type
118             );
119         private string m_duration;
120         private string m_ConnectionName;
121         private string[] m_ConnectionNames;
122         private double m_TX;
123         private double m_RX;
124         private bool m_connected;
125         private IntPtr m_ConnectedRasHandle;
126 
127         RasStats status = new RasStats();
128         public RASDisplay()
129         {
130             m_connected = true;
131 
132             RAS lpras = new RAS();
133             RASCONN lprasConn = new RASCONN();
134 
135             lprasConn.dwSize = Marshal.SizeOf(typeof(RASCONN));
136             lprasConn.hrasconn = IntPtr.Zero;
137 
138             int lpcb = 0;
139             int lpcConnections = 0;
140             int nRet = 0;
141             lpcb = Marshal.SizeOf(typeof(RASCONN));
142 
143             nRet = RAS.RasEnumConnections(ref lprasConn, ref lpcb, ref
144             lpcConnections);
145 
146             if (nRet != 0)
147             {
148                 m_connected = false;
149                 return;
150 
151             }
152 
153             if (lpcConnections > 0)
154             {
155                 //for (int i = 0; i < lpcConnections; i++)
156 
157                 //{
158                 RasStats stats = new RasStats();
159 
160                 m_ConnectedRasHandle = lprasConn.hrasconn;
161                 try
162                 {
163                     RAS.RasGetConnectionStatistics(lprasConn.hrasconn, stats);
164                 }
165                 catch (System.Exception ex)
166                 {
167                     throw ex;
168                 }
169                 finally
170                 {
171 
172 
173                     m_ConnectionName = lprasConn.szEntryName;
174 
175                     int Hours = 0;
176                     int Minutes = 0;
177                     int Seconds = 0;
178 
179                     Hours = ((stats.dwConnectionDuration / 1000/ 3600);
180                     Minutes = ((stats.dwConnectionDuration / 1000/ 60- (Hours * 60);
181                     Seconds = ((stats.dwConnectionDuration / 1000)) - (Minutes * 60- (Hours * 3600);
182 
183 
184                     m_duration = Hours + " hours " + Minutes + " minutes " + Seconds + " secs";
185                     m_TX = stats.dwBytesXmited;
186                     m_RX = stats.dwBytesRcved;
187                     //}
188                 }
189             }
190             else
191             {
192                 m_connected = false;
193             }
194 
195 
196             int lpNames = 1;
197             int entryNameSize = 0;
198             int lpSize = 0;
199             RasEntryName[] names = null;
200 
201             entryNameSize = Marshal.SizeOf(typeof(RasEntryName));
202             lpSize = lpNames * entryNameSize;
203 
204             names = new RasEntryName[lpNames];
205             names[0].dwSize = entryNameSize;
206 
207             uint retval = RAS.RasEnumEntries(nullnull, names, ref lpSize, out lpNames);
208 
209             //if we have more than one connection, we need to do it again
210             if (lpNames > 1)
211             {
212                 names = new RasEntryName[lpNames];
213                 for (int i = 0; i < names.Length; i++)
214                 {
215                     names[i].dwSize = entryNameSize;
216                 }
217 
218                 retval = RAS.RasEnumEntries(nullnull, names, ref lpSize, out lpNames);
219 
220             }
221             m_ConnectionNames = new string[names.Length];
222 
223 
224             if (lpNames > 0)
225             {
226                 for (int i = 0; i < names.Length; i++)
227                 {
228                     m_ConnectionNames[i] = names[i].szEntryName;
229                 }
230             }
231         }
232 
233         public string Duration
234         {
235             get
236             {
237                 return m_connected ? m_duration : "";
238             }
239         }
240 
241         public string[] Connections
242         {
243             get
244             {
245                 return m_ConnectionNames;
246             }
247         }
248 
249         public double BytesTransmitted
250         {
251             get
252             {
253                 return m_connected ? m_TX : 0;
254             }
255         }
256         public double BytesReceived
257         {
258             get
259             {
260                 return m_connected ? m_RX : 0;
261 
262             }
263         }
264         public string ConnectionName
265         {
266             get
267             {
268                 return m_connected ? m_ConnectionName : "";
269             }
270         }
271         public bool IsConnected
272         {
273             get
274             {
275                 return m_connected;
276             }
277         }
278 
279         public int Connect(string Connection)
280         {
281             int temp = 0;
282             uint INTERNET_AUTO_DIAL_UNATTENDED = 2;
283             int retVal = RAS.InternetDial(IntPtr.Zero, Connection, INTERNET_AUTO_DIAL_UNATTENDED, ref temp, 0);
284             return retVal;
285 
286             //取消:668
287         }
288         public void Disconnect()
289         {
290             RAS.RasHangUp(m_ConnectedRasHandle);
291         }
292     }
293 
294 }
295 

 

 

 

 

  2、固定IP接入,代理方式。刚开始有两个方法:a、发送http请求时封装代理IP;b、通过修改注册表方式修改本机IE浏览器代理地址,然后投票。后经测试b方法耗时时间长,而且不能多线程处理最后放弃采用a方法。

      a方法中采用异步调用方法,在最开始使用的是等待返回,后发现因网络延时的问题等待返回会造成程序假死状态,改为异步调用完成后回调方法。但这种方法无法调用控件,通过msdn帮助找到如何:对 Windows 窗体控件进行线程安全调用,控件多线程处理方法有三种,一种非线程安全方式,一种对 Windows 窗体控件进行线程安全调用,一种BackgroundWorker 进行的线程安全调调用。

      使用异步调用完成后回调方法

 

 

ExpandedBlockStart.gif声明异步调用方法和委托
//声明异步调用委托
private delegate string NewTaskDelegate(string voteAdd, string proxyAdd);
//声明委托调用方法
        private static string vote(string voteAdd, string proxyAdd)
        {
            
string html = null;
            
string url = voteAdd;
            
try
            {
                WebRequest req 
= WebRequest.Create(url);
                
// Create a new Uri object.
                if (proxyAdd != null || proxyAdd != "")
                {
                    Uri newUri 
= new Uri("http://" + proxyAdd);
                    WebProxy myProxy 
= new WebProxy();
                    myProxy.Address 
= newUri;
                    req.Proxy 
= myProxy;
                }

                WebResponse res 
= req.GetResponse();
                Stream receiveStream 
= res.GetResponseStream();
                Encoding encode 
= Encoding.GetEncoding("gb2312");
                StreamReader sr 
= new StreamReader(receiveStream, encode);
                
char[] readbuffer = new char[256];
                
int n = sr.Read(readbuffer, 0256);
                
while (n > 0)
                {
                    
string str = new string(readbuffer, 0, n);
                    html 
+= str;
                    n 
= sr.Read(readbuffer, 0256);
                }
            }
            
catch (System.Exception ex)
            {
                html 
= ex.Message;
            }
            
return  proxyAdd + "(^_^)\r\n" + html;
        }

 

 

ExpandedBlockStart.gif声明回调函数
private void updateWindow(IAsyncResult iar)
        {
            NewTaskDelegate task 
= (NewTaskDelegate)iar.AsyncState;
            
            
string result = task.EndInvoke(iar);

            Console.WriteLine(result);
            Interlocked.Decrement(
ref requestCounter);

            
this.SetText(result);
            
this.SetStep();
            
if (requestCounter == 0)
            {
                
this.SetButten(true);
            }
        }

 

 

 

ExpandedBlockStart.gif异步调用完成回调语句
1                 NewTaskDelegate task = vote;
2                 
3                 IAsyncResult asyncResult;
4                 
5                 Interlocked.Increment(ref requestCounter);
6                 AsyncCallback cb = new AsyncCallback(updateWindow);
7                 asyncResult = task.BeginInvoke(this.textBox1.Text, (string)this.listBox1.SelectedItem, cb, task);

 

 

 

ExpandedBlockStart.gifWindows 窗体控件进行线程安全调用声明
delegate void SetStepCallback();
        
private void SetStep()
        {
            
if (this.progressBar1.InvokeRequired)
            {
                SetStepCallback c 
= new SetStepCallback(SetStep);
                
this.Invoke(c) ;
            }
            
else
            {
                
this.progressBar1.PerformStep();
            }
        }

 

 

异步调用控件语句

1 this.SetStep();

 

 

转载于:https://www.cnblogs.com/pfengk/archive/2010/05/15/1735925.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_786790.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

目前开发网站用什么编码比较好?utf-8还是gb2312 ?

我们一般通俗的理解为&#xff1a;utf-8是世界性通用代码&#xff0c;也完美的支持中文编码&#xff0c;如果我们做的网站能让国外用户正常的访问&#xff0c;就最好用utf-8。GB2312属于中文编码&#xff0c;主要针对国内用户使用&#xff0c;如果国外用户访问GB2312编码的网站…

帮助查看本地表单元素样子的网站 - Native Form Elements

为什么80%的码农都做不了架构师&#xff1f;>>> 日期&#xff1a;2013-4-20 来源&#xff1a;GBin1.com 如果你想查看某个表单组建在特定浏览器或者操作系统上的长相的话&#xff0c;这个工具网站 - Native Form Elements 肯定能够帮你忙&#xff01; 它没有任何…

PPTV枯木难支,视频网站如何随波逐流

聚力传媒&#xff08;以下称“PPTV网站”&#xff09;是全球华人领先的、规模最大、拥有巨大影响力的视频媒体。而就在近日&#xff0c;PPTV已确认被阿里巴巴和湖南卫视耗资4亿美元收购&#xff0c;除了不疼不痒的细枝末节&#xff0c;交易基本完成&#xff0c;PPTV妥妥的缴了枪…

如何为网站标题添加logo图片

作为一名运维工程师,是应该具备一些前端的技能,比如html , css等 如何设置网页的图标,让网站看起来更加美观, 前言 对于网站 favicon.ico 图标的大小&#xff0c;建议大家选择 16x16 或者 32x32&#xff0c;再大也是完全没有必要的。效果不见涨&#xff0c;还可能会影响网站加…

24个最精彩的网站设计

每个网站设计者都有他自己的风格。通常他们的喜好和他们的想法都会在设计者的设计中表现出来。 颜色可以影响我们的行为、情感和心灵。事实上&#xff0c;颜色通常用做治疗精神病和其他精神上的行为能力的人。然而&#xff0c;当谈到网页设计&#xff0c;许多设计师会忽视有着神…

分享45个海量免费电子书下载网站

随着网络和信息技术的快速发展&#xff0c;电子书越来越流行。以Amazon Kindle为代表的电子书阅读器的出现改变了人们传统的阅读方式&#xff0c;如同iPod改变人们听音乐一样。如今&#xff0c;很多网上书店也推出了电子书商品&#xff0c;相比传统的纸质书&#xff0c;电子书便…

IIS日志-网站运维的好帮手

阅读目录 开始IIS日志包含了哪些信息IIS日志的配置如何分析IIS日志推荐的IIS日志分析方法IIS日志中的异常记录再谈 scwin32status64寻找性能问题寻找可改进的目标程序架构对IIS日志分析过程的影响对于一个需要长期维护的网站来说&#xff0c;如何让网站长久稳定运行是件很有意义…

分享32个超棒的实用移动网站(mobile website)布局设计

日期&#xff1a;2012-4-16 来源&#xff1a;GBin1.com 移动互联现在已经成为了互联网的新贵&#xff0c;我们不得不考虑如何更好的设计移动互联网。过去5到10年中基本上没有开发设计人员为移动设备设计UI。而到现在几乎每个人都使用智能手机来浏览互联网了。现在是大家认真考…

企业网站 源码 服务邮箱:_企业邮箱申请注册的要求有哪些?_网站建设_创客网络...

随着现在互联网信息化发展的速度不断加快&#xff0c;企业邮箱作为企业之间信息传输的重要工具&#xff0c;其重要性不亚于企业网站&#xff0c;但市场上企业邮箱种类繁多&#xff0c;包含的功能也各不相同&#xff0c;稍有差异&#xff0c;你知道怎么去选择好企业邮箱吗&#…

网站弹窗代码_购物网站设计:做一个实用的电子商务网站

随着线上经济发展&#xff0c;很多企业和商家都有了建立自己的电子商务网站的需求。但是如何让自己的电商购物网站发挥作用&#xff0c;吸引客户下单呢&#xff1f;今天就跟大家科普下电子商务网站设计原理&#xff0c;你需要这样设计电商网站才行&#xff1a;1.商城优惠一个新…

实现基于lnmp的电子商务网站

今天带给大家的是一个实战项目&#xff0c;主要是让大家了解在我们接到一个项目时&#xff0c;我们该怎样做好这个项目&#xff0c;下面看具体内容&#xff1a; 技术说明 LNMP代表的就是&#xff1a;Linux系统下NginxMySQLPHP这种网站服务器架构。 企业级电子商务网站大多是是基…

降本增效|网站性能监控平台监控宝背后功能解读

背景介绍 现如今&#xff0c;云计算技术的广泛应用&#xff0c;让越来越多的传统企业将核心业务部署或迁移到云端。然而&#xff0c;尽管传统企业在上云方面花费巨大&#xff0c;结果却往往很难达到预期。异常复杂的网络接入、链路质量、机房环境都给企业的互联网业务健康带来…

Thinkphp框架搭建手机网站视频教程

2019独角兽企业重金招聘Python工程师标准>>> 我赢职场全球经典Thinkphp框架搭建网站功能&#xff0c;用户登录后&#xff0c;如何在前台显示相应的用户名 连接地址&#xff1a;http://dwz.cn/z9NBy[摘要] 代码中的函数 is_mobile来源于网上&#xff0c;写得挺好的。…

2天内重复访问网站的用户个数,以IP个数为准

今天看到了comm这个命令&#xff0c;解释说可以对比出两个文件中的相同部分 随即&#xff0c;我截取了2016年3月2号&#xff0c;3号每天的总IP&#xff0c;单独存放到一个文件中&#xff0c;名称分别为log02,log03 截取出来的IP我已经进行去除重复&#xff0c;并进行了排序&…

iis7.0如何配置https与ssl安全类型网站

在IIS 7.0 和IIS 6.0中配置SSL的高级别步骤基本相同&#xff1a; 获取合适的证书 在网站创建HTTPS连接 通过向该网站发送请求来进行测试 选择性地配置SSL选项&#xff0c;例如将SSL作为必要条件 本文提供了一些有用的信息&#xff0c;以及如何利用不同的方式启用SSL&#xff1a…

AIBigData four:使用scrapy爬取网站,按照指定的格式存入txt文本的详细过程复盘

用了将近两个星期&#xff0c;终于对scrapy有了初步了解&#xff0c;并且使用scrapy来爬取到了动态加载的网页。再此给自己这两周的学习成果做一个详细的过程复盘&#xff0c;顺带重温下忘掉的知识。 首先看看项目要求。要爬取的是左边的四个大板块里的四个小版块的文章&#x…

使用scrapy做爬虫遇到的一些坑:网站常用的反爬虫策略,如何机智的躲过反爬虫Crawled (403)

在这幅图中我们可以很清晰地看到爬虫与反爬虫是如何进行斗智斗勇的。 在学习使用爬虫时&#xff0c;我们制作出来的爬虫往往是在“裸奔”&#xff0c;非常的简单。 简单低级的爬虫有一个很大的优点&#xff1a;速度快&#xff0c;伪装度低。如果你爬取的网站没有反爬机制&#…

马云称自己的成就无关科技与钱;任正非:外籍员工可当华为 CEO,但有条件;雅虎宣布逐步关闭雅虎群组网站 | EA周报...

EA周报2019年10月18日每个星期7分钟&#xff0c;元宝带你喝一杯IT人的浓缩咖啡&#xff0c;了解天下事、掌握IT核心技术。热点大事件丰巢回应小学生用照片“刷脸”取件&#xff1a;测试版&#xff0c;已第一时间下线有报道称“小学生发现丰巢快递柜刷脸取件漏洞&#xff0c;用照…

学习nginx所遇到的坑:Mac如何在nginx上创建新的网站?

首先&#xff0c;掌握基本的知识。 改配置文件&#xff1a; vi /usr/local/etc/nginx/nginx.conf 改html文件&#xff1a;vi /usr/local/Cellar/nginx/1.15.8/html/**.html 重启nginx: nginx -s reload -c 首先改动配置文件 &#xff0c;找到以下图片中的代码 从注释中我们…

第一次上传成功jsp网站总结

今天费了一下午功夫才上传成功一个jsp网站&#xff0c;现在总结下&#xff1a; 一般jsp网站分为两部分&#xff1a;1&#xff0c;网站部分 2&#xff0c;数据库部分。 要想在外网看到自己上传的jsp网站&#xff1a; 1&#xff0c;要有一个域名和空间&#xff0c;我今天用的是…