高手请进:局域网内如何根据ip地址查询计算机名称(不是本机),如何用C#实现?
例如,已知一台机器的ip地址为10.41.105.30,如何确定其计算机名称?谢谢!

解决方案 »

  1.   

    public string GetName(string myip)
    {
    IPAddress myscanip=IPAddress.Parse(myip);
    IPHostEntry myscanhost = Dns.GetHostByAddress( myscanip );
    string name = myscanhost.HostName.ToString();
    return name;
    }
      

  2.   

    nbtstat   -a   192.168.0.1  执行CMD命令
      

  3.   

    http://www.chenjiliang.com/Article/View.aspx?ArticleID=692&TypeID=84
      

  4.   

    //using System.Diagnostics;
                Process proc = new Process();
                proc.StartInfo.FileName = @"ping.exe";
                proc.StartInfo.Arguments = "command"; //command 为dos 命令
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardInput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.CreateNoWindow = true;
                proc.Start();
                string output = proc.StandardOutput.ReadToEnd();
                proc.Dispose();            string pingrst = "";
                if (output.IndexOf("(0% loss)") != -1)
                    pingrst = "连接";
                else if (output.IndexOf("Destination host unreachable.") != -1)
                    pingrst = "无法到达目的主机";
                else if (output.IndexOf("Request timed out.") != -1)
                    pingrst = "超时";
                else if (output.IndexOf("Unknown host") != -1)
                    pingrst = "无法解析主机";
                else
                    pingrst = output;            MessageBox.Show(pingrst);//只要你会用dos命令找到就研究一下吧
      

  5.   

    @m777((我的家乡江西新余))
    好像不行哦,我以前用這個,好像只能得到IP地址哦。你有沒有測試過啊!