C# 获取局域网中所有计算机的IP和计算机名。

luohuayouy 2012-12-10 01:57:58

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Collections;//ArrayList用
using System.Threading;
using System.Net;


namespace ALLIP2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.startIP = startIP;
this.endIP = endIP;
this.ipPrefix = ipPrefix;
computerList = new ArrayList();

}
private int startIP = 0;
private int endIP = 0;
private string ipPrefix = "";
private ArrayList computerList = null;

public void ScanComputers()
{
for(int i=startIP;i<=endIP;i++)
{
string scanIP = ipPrefix +"."+i.ToString();

IPAddress myScanIP = IPAddress.Parse(scanIP);

IPHostEntry myScanHost = null;

string[] arr = new string[2];

try
{
myScanHost = Dns.GetHostByAddress(myScanIP);
}

catch
{
continue;
}

if (myScanHost != null)
{
arr[0] = myScanHost.HostName;

arr[1] = scanIP;

computerList.Add(arr);
MessageBox.Show(myScanHost.HostName.ToString());
MessageBox.Show(scanIP.ToString());
}
}
}

private void button1_Click(object sender, EventArgs e)
{
Form1 cai = new Form1("192.168.1", 134, 135);
Thread thScan = new Thread(new ThreadStart(cai.ScanComputers));
thScan.Start();


}

}
}
编译时提示错误说这一句“ Form1 cai = new Form1("192.168.1", 134, 135); ” Form1没有采用3个参数的重载。求大侠指教。
...全文
175 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧