从internet获取手机号所在地的源代码
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace getInfoFromInternet
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(176, 24);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private System.Text.RegularExpressions.Regex r=
new System.Text.RegularExpressions.Regex(@"[\u4e00-\u9fa5]+");
System.Text.RegularExpressions.Match m = null;
private string getMsg(string originalMsg)
{
m= r.Match(originalMsg);
string msg = ((System.Text.RegularExpressions.Capture)(((System.Text.RegularExpressions.Group)(m)))).Value;
return msg;
}
private string query = "http://mobile.zol.com.cn/search.php";
private string data1="status=search&searchkeyword=";
private string data2="&searchcategory=&Submit="
+System.Web.HttpUtility.UrlEncode("搜索");
private void getInfo(string which)
{
for(int num=0;num<10000;num++)
{
string strNum = "13" + which + num.ToString().PadLeft(4,'0') + "0000";
string adscription=null;
string type = null;
System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString());
System.Diagnostics.Debug.WriteLine(strNum);
string postdata = data1+System.Web.HttpUtility.UrlEncode(strNum)+data2;
System.Net.HttpWebRequest req =
(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(query);
req.Method = "POST";
req.ContentLength= postdata.Length;
req.ContentType = "application/x-www-form-urlencoded";
System.Net.NetworkCredential myCred =
new System.Net.NetworkCredential("user","pwd","domain");
System.Net.WebProxy proxyObject = new System.Net.WebProxy("192.168.1.1",8080);
proxyObject.Credentials = myCred;//myCache;
req.Proxy = proxyObject;
System.IO.StreamWriter sw = new System.IO.StreamWriter(req.GetRequestStream());
sw.Write(postdata);
sw.Close();
System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader
( resp.GetResponseStream(),System.Text.Encoding.Default);
string line = sr.ReadLine();
while(line!=null)
{
if(line.IndexOf("归属地:")>0)
{
adscription = getMsg(sr.ReadLine());
System.Diagnostics.Debug.WriteLine(adscription);
}
if(line.IndexOf("手机客户类别")>0)
{
type=getMsg(sr.ReadLine());
System.Diagnostics.Debug.WriteLine(type);
break;
}
line = sr.ReadLine();
}
resp.Close();
sr.Close();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(
"server=localhost;uid=sa;pwd=pwd;database=mobileNumber;");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(
"INSERT INTO t_mn(number,adscription,type)values('"+strNum+"','"+adscription+"','"+type+"')",conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
conn.Dispose();
System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString());
}
}
private void get5()
{
getInfo("5");
}
private void get6()
{
getInfo("6");
}
private void get7()
{
getInfo("7");
}
private void get8()
{
getInfo("8");
}
private void get9()
{
getInfo("9");
}
private void get0()
{
getInfo("0");
}
private void get1()
{
getInfo("1");
}
private void get2()
{
getInfo("2");
}
private void get3()
{
getInfo("3");
}
private void button1_Click(object sender, System.EventArgs e)
{
System.Threading.Thread t0 = new System.Threading.Thread(new System.Threading.ThreadStart(get0));
System.Threading.Thread t1 = new System.Threading.Thread(new System.Threading.ThreadStart(get1));
System.Threading.Thread t2 = new System.Threading.Thread(new System.Threading.ThreadStart(get2));
System.Threading.Thread t3 = new System.Threading.Thread(new System.Threading.ThreadStart(get3));
System.Threading.Thread t5 = new System.Threading.Thread(new System.Threading.ThreadStart(get5));
System.Threading.Thread t6 = new System.Threading.Thread(new System.Threading.ThreadStart(get6));
System.Threading.Thread t7 = new System.Threading.Thread(new System.Threading.ThreadStart(get7));
System.Threading.Thread t8 = new System.Threading.Thread(new System.Threading.ThreadStart(get8));
System.Threading.Thread t9 = new System.Threading.Thread(new System.Threading.ThreadStart(get9));
t0.Start();
t1.Start();
t2.Start();
t3.Start();
t5.Start();
t6.Start();
t7.Start();
t8.Start();
t9.Start();
}
}
}