C # web page scalpers (proxy IP voting)

Source: Internet
Author: User

@ Chen Yuxiang and @ Chen Yuxiang wrote a ticket Generator for a week to deliver the software testing course.

The PPT is not very good. Put it in the resource. The PPT address is:

Source Code address: http://download.csdn.net/detail/a8887396/5344103

Voting effect:

Ticket address: (valid for six months)

Http://mwangbobo.jingdianet.com/Default.aspx

Main Code:

Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; using system. io; using mshtml; using system. net; using system. runtime. interopservices; namespace: {public partial class form1: FORM {[dllimport (@ "wininet", setlasterror = true, charset = charset. auto, entrypoint = "internetse Toption ", callingconvention = callingconvention. stdcall)] // instant refresh ieset public static extern bool internetsetoption (INT hinternet, int dmoption, intptr lpbuffer, int dwbufferlength); // whether it can be connected to the Internet [dllimport ("wininet. DLL ")] public extern static bool internetgetconnectedstate (Out int description, int reservedvalue); // return false to connect to the Internet public static bool isconnectedtointernet () {int DESC; R Eturn internetgetconnectedstate (Out DESC, 0);} int count_all = 0; // Number of votes bool is_start = false; // start sign bool is_interval = false; // whether to use the time interval bool is_proxy = false; // bool is_ip_changed = false; string url_str = "http://mwangbobo.jingdianet.com/Default.aspx"; // specify the URL of the vote // string url_str = "http: // localhost: 4128/website1/default. aspx "; string file_path; // text path of the proxy IP string [] IP = new string [1024];/ /Proxy IP // string [] Port = new string [1024]; // proxy IP port int count_ip = 0; // Number of proxy IP addresses public form1 () {initializecomponent (); webbrowser1.navigate (url_str ); // jump to the page}/* ======================== voting module ============== =====* // click the start button private void btn_start_click (Object sender, eventargs e) {If (! Isconnectedtointernet () // check whether the network card status is connected to the Internet. If you unplug the network cable, an error will occur, not including setting proxy IP errors, leading to failure to open web pages {MessageBox. show ("cannot connect to the Internet"); return;} // If (is_start | webbrowser1.url = NULL | webbrowser1.url. tostring ()! = Url_str) // After the start, it cannot start to become invalid or the current page is not a voting page invalid {// return;} is_start = true; int interval = 0; bool I = int. tryparse (text_interval.text, out interval); // obtain the refresh interval if (! I | interval = 0) {// The acquisition interval fails or the interval is 0. The timer is_interval = false is not used; complete_timer.interval = 3000; // The webpage loading timer prevents loading failures on the webpage.} Else {vote_timer.interval = interval * 1000; // because is_interval is microsecond = true; complete_timer.interval = interval * 1000 + 3000; // webpage loading timer} If (check_ip.checked) {is_proxy = true;} If (Int. tryparse (text_count.text.tostring (), Out count_all) // If the input is a valid number {If (count_all> 0) // The number of votes is greater than 0 {If (is_proxy) count_all ++; // no matter whether the proxy IP address is used or not, add text_remain.text = convert. tostring (count_all); // com Plete_timer.enabled = true; // start loading completion time if (is_interval) {vote_timer.enabled = true; // start timer} else {vote (); // directly vote when no timer is used} else {is_start = false; is_interval = false; is_proxy = false; vote_timer.enabled = false ;}} // vote for the timer event private void vote_timer_tick (Object sender, eventargs e) {If (! Is_start | count_all = 0) return; vote_timer.enabled = false; vote () ;}// name number string [] Xing = {"Zhao", "Qian ", "Sun", "Li", "Zhou", "Wu", "Zheng", "Wang", "Feng", "Chen", "wei", "wei ", "Jiang", "shen", "Han", "Yang", "zhu", "Qin", "you", "Xu", "he", "Lu ", "Shi", "Zhang", "Kong", "Cao", "Yan", "Hua", "Jin", "wei", "Tao", "Jiang ", "Qi", "xie", "Yan", "Yu", "bai", "water", "dou", "Zhang", "Cloud", "Su ", "pan", "Ge", "Jun", "fan", "peng", "Lang"}; string [] Ming = {"changrui", "quanlong ", "Jianli", "taifu", "changcai", "hongliang", "changxun", "Zhuo Zhen "," Chang zhe "," Cheng zhe "," Zhuo Xun "," Wu Long "," ice "," bin "," Shu Qi "," Ji Fang ", "Yuan Feng", "Mei Ru", "Shirley", "Na Rui", "Qian Ru", "Pei Xiu", "Jing Yao", "Yi Jie", "Qiao Mei ", "Qing", "Zheng guang", "Si Yuan", "Qing", "Zhi Kun", "Xi Jun", "Wan Rou", "elegant", "Jun gang ", "Zhu Ying", "lei", "Xi", "Qi", "Jun"}; string [] haomaf = {"138", "139", "150 "}; // vote: Select checkbox to fill in the form and submit private void vote () {// if the number of votes has been used up, initialize these values and then stop if (count_all <= 0) {// is_start = false; return;} text_remain.text = convert. tostring (-- count_all ); // The remaining number of times-1 and displayed to the remaining number of times text. If (is_proxy & count_all> 0) {setproxy (IP [count_all-1]);} random r = new random (); string q = Xing [R. next (48)]; // the random surname string K = Ming [R. next (39)]; // randomly selected name application. doevents (); string haoma = haomaf [R. next (3)]; // generate a random number of three-digit for (INT I = 0; I <8; I ++) // generate {haoma + = R. next (10);} complete_timer.enabled = true; // start loading the webpage. Try {// the following code may throw an exception, that is, the required meta cannot be loaded on the webpage. Prime time. // It Ends directly when an exception occurs, but loading the timer on the webpage has started. // select the second option action click webbrowser1.document. getelementbyid ("maincontent_radiobuttonlist1_2 "). invokemember ("click"); // application. doevents (); // enter the random name webbrowser1.document. getelementbyid ("maincontent_username "). innertext = q + k; // application. doevents (); // enter the random number webbrowser1.document. getelementbyid ("maincontent_userphone "). innertext = haoma; // application. doeven TS (); // select the submit button action click webbrowser1.document. getelementbyid ("maincontent_okbutton "). invokemember ("click"); application. doevents ();} catch (system. exception ex) {// is_start = false; // MessageBox. show ("the voting object is not found on the page", "error") ;}// webbrowser?documentcompleted in the successful loading stage of the Web page. If yes, the vote is made again. Private void webbrowserincludocumentcompleted (Object sender, webbrowserdocumentcompletedeventargs e) {complete_timer.enabled = false; // Kai if (! Is_start) return; If (count_all> 0) // continue voting {If (is_interval) {// vote_timer.enabled = true if the interval timer is used ;} else {// no interval timer is used to directly start voting vote () ;}} else // The vote has been cast, {is_start = false; // The vote flag is 0 is_interval = false; if (is_proxy) {disproxy (); is_proxy = false;} vote_timer.enabled = false; // whether there is a timer or not, the sign is 0 complete_timer.enabled = false; MessageBox. show ("Vote finished") ;}// webbrowser navigated stage: Control item When a new file is viewed and the file is loaded, navigating indicates private void webbrowser1_navigated (Object sender, webbrowsernavigatedeventargs e) {ihtmlwindow2 win = (ihtmlwindow2) webbrowser1.document. window. domwindow; string S = @ "function confirm () {"; S + = @ "Return true;"; S + = @"}"; S + = @ "function alert () {}"; win.exe cscript (S," JavaScript ") ;}// the end button private void btn_end_click (Object sender, eventargs e) {is_sta RT = false; is_interval = false; is_proxy = false; disproxy (); vote_timer.enabled = false; MessageBox. show ("Vote terminated ");} /* = proxy IP module = = 1 import proxy IP * 2 use proxy IP * // The text format of the button to import proxy IP must be IP: port to correctly read private void btn_ip_click (Object sender, eventargs e) {openfiledialog filedialog1 = new openfiledialog (); // file selection box filedialog1.initialdirectory = "D ://"; // The path opened by default. You can change the filedial Og1.filter = "text file (*. TXT) | *. TXT | all files (*. *) | *. * "; filedialog1.filterindex = 1; filedialog1.restoredirectory = true; If (filedialog1.showdialog () = dialogresult. OK) // Click OK to select the file {file_path = filedialog1.filename;} else {// file_path = NULL; return;} // open the file and obtain the IP address and port if (file_path.length! = 0) {filestream FS = new filestream (file_path, filemode. open); // open the file streamreader m_streamreader = new streamreader (FS); // read the file m_streamreader.basestream.seek (0, seekorigin. begin); // locate the File Read location string strline = m_streamreader.readline (); // read the first line int I = 0; do {IP [I] = strline. split ('@') [0]; // textbox1.text + = IP [I]; strline = m_streamreader.readline (); // read the next row I ++;} while (strline! = NULL & strline! = ""); M_streamreader.close (); // close the reader m_streamreader.dispose (); // release the resource FS. close (); // close the file stream FS. dispose (); // release the resource count_ip = I; // record the number of proxy IP addresses} // click the proxy IP address checkbox. If the proxy IP address is used, write the number of proxy IP addresses to private void check_ip_checkedchanged (Object sender, eventargs e) {If (check_ip.checked = true) {text_count.text = convert. tostring (count_ip); text_count.enabled = false;} else {text_count.enabled = true ;}// sets the proxy IP private void setproxy (string IP) {If (IP = NULL | IP = "") return; // If the IP address is null, return try {// obtain the Registry object Microsoft. win32.registrykey rk = Microsoft. win32.registry. currentuser. opensubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Internet Settings", true); // sets the availability of the agent rk. setvalue ("proxyenable", 1); // sets the proxy IP address and port rk. setvalue ("proxyserver", ip); rk. flush (); rk. close (); // enable internetsetoption (0, 39, intptr. zero, 0); internetsetoption (0, 37, intptr. zero, 0); // internetsetoption (null, internet_option_settings_changed, null, null); // internetsetoption (null, internet_option_refresh, null, null); // is_ip_changed = true; // webbrowser1.refresh (); // webbrowser1.document. execcommand ("refresh", false, null);} catch (system. exception ex) {}} private void disproxy () {try {Microsoft. win32.registrykey rk = Microsoft. win32.registry. currentuser. opensubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Internet Settings", true); // sets the availability of the agent rk. setvalue ("proxyenable", 0); // sets the proxy IP address and port rk. setvalue ("proxyserver", ""); rk. flush (); rk. close (); // is_ip_changed = false; // enable internetsetoption (0, 39, intptr. zero, 0); internetsetoption (0, 37, intptr. zero, 0);} catch (system. exception ex) {}} private void complete_timer_tick (Object sender, eventargs e) {// count_all --; complete_timer.enabled = false; disproxy (); webbrowser1.navigate (url_str ); // webbrowser1_documentcompleted (null, null); // MessageBox. show ("loading timeout ");}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.