⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formmain.cs

📁 这是一个手机归属第的查询
💻 CS
字号:
/************************************************************
IP数据库、手机归属地查询软件完整源代码(C#)
  Author: rssn
  Email : rssn@163.com
  QQ    : 126027268
  Blog  : http://blog.csdn.net/rssn_net/
 ************************************************************/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Net;

using Hebust;

namespace IpSearch
{
	/// <summary>
	/// FormMain 的摘要说明。
	/// </summary>
	public class FormMain : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox TextResult;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button bDoSearch;
		private System.Windows.Forms.TextBox tbKeyword;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox mpKw;
		private System.Windows.Forms.Label label2;
		//数据文件名
		private string [] IpDataFilePath={"CoralWry.Dat","QQWry.dat"};
		private string [] MpDataFilePath={"MpData.dat","MpData2.dat"};
		public FormMain()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.TextResult = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.mpKw = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.tbKeyword = new System.Windows.Forms.TextBox();
			this.bDoSearch = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// TextResult
			// 
			this.TextResult.AutoSize = false;
			this.TextResult.Font = new System.Drawing.Font("Courier New", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.TextResult.Location = new System.Drawing.Point(2, 84);
			this.TextResult.Multiline = true;
			this.TextResult.Name = "TextResult";
			this.TextResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.TextResult.Size = new System.Drawing.Size(482, 182);
			this.TextResult.TabIndex = 0;
			this.TextResult.Text = "";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.mpKw);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.tbKeyword);
			this.groupBox1.Controls.Add(this.bDoSearch);
			this.groupBox1.Location = new System.Drawing.Point(4, 6);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(480, 72);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "查询条件";
			// 
			// mpKw
			// 
			this.mpKw.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.mpKw.Location = new System.Drawing.Point(82, 42);
			this.mpKw.Name = "mpKw";
			this.mpKw.Size = new System.Drawing.Size(268, 21);
			this.mpKw.TabIndex = 9;
			this.mpKw.Text = "";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(14, 44);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(60, 17);
			this.label2.TabIndex = 8;
			this.label2.Text = "手机号段:";
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(14, 18);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 17);
			this.label1.TabIndex = 7;
			this.label1.Text = "IP地址:";
			// 
			// tbKeyword
			// 
			this.tbKeyword.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.tbKeyword.Location = new System.Drawing.Point(82, 16);
			this.tbKeyword.Name = "tbKeyword";
			this.tbKeyword.Size = new System.Drawing.Size(268, 21);
			this.tbKeyword.TabIndex = 6;
			this.tbKeyword.Text = "";
			// 
			// bDoSearch
			// 
			this.bDoSearch.Location = new System.Drawing.Point(372, 16);
			this.bDoSearch.Name = "bDoSearch";
			this.bDoSearch.Size = new System.Drawing.Size(96, 23);
			this.bDoSearch.TabIndex = 5;
			this.bDoSearch.Text = "查询(&S)";
			this.bDoSearch.Click += new System.EventHandler(this.bDoSearch_Click);
			// 
			// FormMain
			// 
			this.AcceptButton = this.bDoSearch;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(488, 270);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.TextResult);
			this.MaximizeBox = false;
			this.Name = "FormMain";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "纯真IP、手机归属地查询器";
			this.Load += new System.EventHandler(this.FormMain_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			Application.Run(new FormMain());
		}

		private void FormMain_Load(object sender, System.EventArgs e)
		{
			//光标放在文本框
			tbKeyword.Focus();
		}

		private void bDoSearch_Click(object sender, System.EventArgs e)
		{
			string ipString=tbKeyword.Text.Trim();
			string mpString=mpKw.Text.Trim();
			TextResult.Text="";
			string fn;
			//查询IP
			if(ipString.Length>0)
			{
				fn=IpDataFilePath[0];
				foreach(string fnm in IpDataFilePath)
				{
					if(File.Exists(fnm))
					{
						fn=fnm;
						break;
					}
				}
				try
				{
					IpLocation ipl=IpLocator.GetIpLocation(fn,ipString);
					TextResult.Text+="IP地址段: "+IpLocator.IntToIpString(ipl.IpStart)+" - "+IpLocator.IntToIpString(ipl.IpEnd)+"\r\n";
					TextResult.Text+="IP所在地: "+ipl.Country+" "+ipl.City+"\r\n\r\n";
				}
				catch(Exception ex)
				{
					if(ex.Message=="文件不存在!")
						MessageBox.Show("IP数据库打开失败,请确认程序目录下存在"+IpDataFilePath[0]+"文件!","纯真IP、手机归属地查询器");
					else
					{ /*意外错误*/}
				}
			}
			//查询手机归属地
			if(mpString.Length>0&&System.Text.RegularExpressions.Regex.IsMatch(mpString, @"^-?\d+$"))
			{
				//如果多于7位
				if(mpString.Length>7)
					mpString=mpString.Substring(0,7);
				int num=Int32.Parse(mpString);
				fn=MpDataFilePath[0];
				foreach(string fnm in MpDataFilePath)
				{
					if(File.Exists(fnm))
					{
						fn=fnm;
						break;
					}
				}
				try
				{
					MpLocation mpl=MpLocator.GetMpLocation(fn,num);
					TextResult.Text+="号码段: "+mpl.NumStart+" - "+mpl.NumEnd+"\r\n";
					TextResult.Text+="归属地: "+mpl.Location+"\r\n\r\n";
				}
				catch(Exception ex)
				{
					if(ex.Message=="文件不存在!")
						MessageBox.Show("手机号段数据库打开失败,请确认程序目录下存在"+MpDataFilePath[0]+"文件!","纯真IP、手机归属地查询器");
					else
					{ /*意外错误*/}
				}
			}
		}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -