多线程IP获取工具(C#)

以前帮一个朋友写的“IP采集工具”!

Control.CheckForIllegalCrossThreadCalls = false;

多线程,测试后还比较稳定。

500线程时候,CPU5%左右,内存50多M,1W数据需要6分多钟验证完毕。

 

以下是部分代码:

 1 public string Getms(string url = "https://www.baidu.com/", string proxy = null)
 2         {
 3             Stopwatch sw = new Stopwatch();
 4             try
 5             {
 6                 HttpHelpers helper = new HttpHelpers();
 7                 HttpItems items = new HttpItems();
 8                 HttpResults hr = new HttpResults();
 9                 items.URL = url;
10                 items.ResultType = ResultType.So;
11                 items.ProxyIp = proxy;
12                 sw.Start();
13                 hr = helper.GetHtml(items);
14                 sw.Stop();
15                 if (hr.StatusCode == HttpStatusCode.OK)
16                 {
17                     return sw.ElapsedMilliseconds.ToString();
18                 }
19                 return "-1";
20             }
21             catch (Exception)
22             {
23                 return "-500";
24             }
25         }
View Code
 1 //打开注册表键 
 2             Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
 3             int count = 5;
 4             while (rk.GetValue("ProxyServer") == null && count != 0)
 5             {
 6                 count = count - 1;
 7                 //设置代理IP和端口 
 8                 rk.SetValue("ProxyEnable", 1);
 9                 rk.SetValue("ProxyServer", ip + ":" + port);
10             }
11             API.InternetSetOptionA(0, 39, 0, 0);
View Code
posted @ 2016-03-24 18:33  inscan  阅读(928)  评论(1编辑  收藏  举报