日期:2014-05-20  浏览次数:20806 次

扫描局域网在线计算机(高分)
我想用C#写一个扫描的局域网在线PC的程序,不知道怎么着手。有那位大哥给一个思路。

该程序只要能获得所有在线计算机的IP地址或者计算机名列表就行了(注意是   在线   ,去获得DNS我毫无意义)。

------解决方案--------------------
http://hi.baidu.com/dovebo/blog/item/f2b93dd3144d07003af3cf89.html


------解决方案--------------------
多线程ping IP不就可以了吗、具体写法看看MSND
------解决方案--------------------
给你一个精品的

FOR /L %%i IN (1, 1, 110) DO ping -a -n 1 -w 10 192.168.11.%%i

192.168.11. 改成你的网段



------解决方案--------------------
[DllImport( "Netapi32 ", CharSet=CharSet.Unicode)]
private static extern int NetServerEnum(
string servername, // must be null
int level, // 100 or 101
out IntPtr bufptr, // pointer to buffer receiving data
int prefmaxlen, // max length of returned data
out int entriesread, // num entries read
out int totalentries, // total servers + workstations
uint servertype, // server type filter
[MarshalAs(UnmanagedType.LPWStr)]
string domain, // domain to enumerate
IntPtr resume_handle );
可以获取局域网中所有计算机,SQL SERVER服务器,打印服务,时间服务等

------解决方案--------------------
还有一法,就是用DOS命令:
cmd /c net view > 0.txt
这方法我以前也给CSDN上的朋友说过,现在忘了源码,只好重新帮你写,测试了
代码如下:
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo();
psi.FileName = "cmd ";
psi.Arguments = "/c net view > 0.txt ";
psi.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
Application.DoEvents();
System.Diagnostics.Process.Start(psi);
System.IO.StreamReader sr = null;
bool dosrun = true;
while(dosrun)
{
Application.DoEvents();
try
{
System.Threading.Thread.Sleep(1000);
sr = new System.IO.StreamReader(Application.StartupPath
+ "\\0.txt ");
dosrun =false;
}
catch
{
dosrun =true;
}
}
ArrayList ar=new ArrayList();
string str=sr.ReadLine();
while(str!=null)
{
Application.DoEvents();
if(str.StartsWith( "\\\\ "))
ar.Add(str.Substring(2));
str=sr.ReadLine();
}
lbComputers.DataSource=ar;

------解决方案--------------------
private void button1_Click(object sender, System.EventArgs e)
{
IPHostEntry myHost = new IPHostEntry();
try
{
this.richTextBox1.Text = " ";
myHost = Dns.GetHostByName(Dns.GetHostName());
textBox1.Text = myHost.HostName.ToString();
for(int i=0; i <myHost.AddressList.Length;i++)
{
richTextBox1.AppendText( "本地主机IP地址-> " + myHost.AddressList[i].ToString()+ " ");
}
}
catch(Exception error)
{
MessageBox.Show(error.Message);
}

}
------解决方案--------------------
C#实现网段扫描
摘要

想必大家对小榕时光等扫描器都非常熟悉了,有没有自己写一个的冲动。最近微软推实施了.NET战略方案,C#是主推语言,你们是否有兴趣用C#来实现对局域网IP地址的扫描,尝试一下自己写的快乐,那么请跟我来。


--------------------------------------------

目录

1.使用的类

2.获取本地主机IP地址

3.远程查询

4.实现网段的扫描


--------------------------------------------