private static void GetAllHostName()
{
try
{
Process process = new Process();
process.StartInfo.FileName = "net";
process.StartInfo.Arguments = "view";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
while (!process.StandardOutput.EndOfStream)
{
string str = process.StandardOutput.ReadLine();
if (str.StartsWith(@"\\"))
{
try
{
string hostName = str.Substring(2, str.IndexOf(' ') - 2);//主机名称
string ip = Dns.GetHostAddresses(hostName.Trim())[0].ToString();//IP地址
LANIPHostNameLink link = new LANIPHostNameLink( ip,hostName);
m_list.Add(hostName);
m_IPList.Add(ip);
m_LANIPNameDic.Add(ip,hostName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}