我想在WEB下实现网段的扫描:
比如:我输入192.168.1.2---192.168.3.254(跨网段)
然后开启多线程把存在的IP地址在指定文本框中显示出来.
问了几个朋友说很难实现!!!
请问:要用到何种技术实现?应该注意什么问题?
如果能提供相关源代码必送分!
比如:我输入192.168.1.2---192.168.3.254(跨网段)
然后开启多线程把存在的IP地址在指定文本框中显示出来.
问了几个朋友说很难实现!!!
请问:要用到何种技术实现?应该注意什么问题?
如果能提供相关源代码必送分!
using System.Net;
using System.Net.Sockets;
using System.Threading; private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
} private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(iptest));
t.IsBackground = true;
t.Start();
} private void iptest()
{
string[] startip = textBox1.Text.Split(new char[] { '.' });
string[] endip = textBox2.Text.Split(new char[] { '.' });
string changeip = startip[2];
string endchangeip = endip[2];
string lastip = startip[3];
string endlastip = endip[3];
for (int i = Convert.ToInt32(changeip); i <= Convert.ToInt32(endchangeip); i++)
{
if (i != Convert.ToInt32(endchangeip))
{
for (int m = Convert.ToInt32(lastip); m < 255; m++)
{
try
{
string testip = startip[0] + "." + startip[1] + "." + i.ToString() + "." + m.ToString();
IPAddress ip = IPAddress.Parse(testip);
IPHostEntry iphost = Dns.GetHostByAddress(ip);
if (iphost.HostName != null && iphost.HostName != "")
{
listBox1.Items.Add(iphost.HostName);
Application.DoEvents();
}
}
catch
{ }
}
}
else
{
for (int j = 0; j <= Convert.ToInt32(endchangeip); j++)
{
try
{
string testip = startip[0] + "." + startip[1] + "." + i.ToString() + "." + j.ToString();
IPAddress ip = IPAddress.Parse(testip);
IPHostEntry iphost = Dns.GetHostByAddress(ip);
if (iphost.HostName != null && iphost.HostName != "")
{
listBox1.Items.Add(iphost.HostName);
}
}
catch
{ }
}
} }
}
根据输入的地址如果能得到返回的主机名说明主机存活,
据说用socket地址+端口可以扫描所有的端口,
我是在WEB 下实现 ,不是 WIN应用程序下实现.....