根據IP地址獲得主機名稱
// .NET 1.1 ~
System.Net.IPHostEntry host = System.Net.Dns.GetHostByAddress("192.168.0.1"); // [msdn]
Console.WriteLine(host.HostName);

// .NET 2.0 ~
System.Net.IPHostEntry host = System.Net.Dns.GetHostEntry("192.168.0.1"); // [msdn]
Console.WriteLine(host.HostName);

取得本機IP
static void Main(string[] args)
{
  // 顯示主機名
  string hostname = Dns.GetHostName();
  Console.WriteLine("hostname = {0}", hostname);

  // 顯示每個IP地址
  IPHostEntry hostent = Dns.GetHostByName(hostname); // 主機信息
  IPAddress[] addrs = hostent.AddressList; // IP地址數組
  foreach ( IPAddress ip in hostent.AddressList )
  {
    Console.WriteLine("Address: {0}", ip);
  } // foreach
}
 

VB, VBA