不悔,谢谢你啦 嘿嘿
找到解决方法了,贴出来,共享下
public class ComputerAddressInfo
{
//ComputerAddressInfo cai = new ComputerAddressInfo("10.25.17",42,53);
private int startIP = 0;
private int endIP = 0;
private string ipPrefix = "";
private ArrayList computerList = null;
public ComputerAddressInfo(string ipPrefix,int startIP,int endIP)
{
this.startIP = startIP;
this.endIP = endIP;
this.ipPrefix = ipPrefix;
computerList = new ArrayList();
}
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;
Console.WriteLine(arr[0]+" "+arr[1]);
computerList.Add(arr);
}
}
}
}
找到解决方法了,贴出来,共享下
public class ComputerAddressInfo
{
//ComputerAddressInfo cai = new ComputerAddressInfo("10.25.17",42,53);
private int startIP = 0;
private int endIP = 0;
private string ipPrefix = "";
private ArrayList computerList = null;
public ComputerAddressInfo(string ipPrefix,int startIP,int endIP)
{
this.startIP = startIP;
this.endIP = endIP;
this.ipPrefix = ipPrefix;
computerList = new ArrayList();
}
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;
Console.WriteLine(arr[0]+" "+arr[1]);
computerList.Add(arr);
}
}
}
}
希望,是走出来的!!!