111,120
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Threading;
namespace SearchIp
{
public partial class Form1 : Form
{
private string ipStr;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label4.Text = "";
ipStr = textBox1.Text;
Thread t = new Thread(new ThreadStart(SearchThread));
t.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Maximum = 364875;
}
public void SearchThread()
{
string[] ipfd = ipStr.Split('.');
int ip1 = Convert.ToInt32(ipfd[0]);
int ip2 = Convert.ToInt32(ipfd[1]);
int ip3 = Convert.ToInt32(ipfd[2]);
int ip4 = Convert.ToInt32(ipfd[3]);
string sqlcmd="select * from IP_Address where IPStart like '%"+(ip1+"."+ip2)+"%'";
if(ip1 <12)
sqlcmd="select * from IP_Address where IPStart like '%"+ip1+"%'";
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=IP.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand(sqlcmd, con);
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
int ts = Convert.ToInt32(dr["Code"]);
this.Invoke((MethodInvoker)delegate
{
progressBar1.Value = ts;
progressBar1.Refresh();
label4.Text = ts + "";
label4.Refresh();
});
string[] IPS = dr["IPStart"].ToString().Split('.');
string[] IPE = dr["IPEnd"].ToString().Split('.');
int ips1 = Convert.ToInt32(IPS[0]);
int ips2 = Convert.ToInt32(IPS[1]);
int ips3 = Convert.ToInt32(IPS[2]);
int ips4 = Convert.ToInt32(IPS[3]);
int ipe1 = Convert.ToInt32(IPE[0]);
int ipe2 = Convert.ToInt32(IPE[1]);
int ipe3 = Convert.ToInt32(IPE[2]);
int ipe4 = Convert.ToInt32(IPE[3]);
if (ip1 >= ips1 && ip2 >= ips2 && ip3 >= ips3 && ip4 >= ips4 &&
ip1 <= ipe1 && ip2 <= ipe2 && ip3 <= ipe3 && ip4 <= ipe4)
{
this.Invoke((MethodInvoker)delegate
{
label2.Text = label2.Text + dr["IP_Address"].ToString();
});
break;
}
Thread.Sleep(2);
}
con.Close();
cmd.Dispose();
dr.Dispose();
}
}
}