C#获得本机的计算机名及IP地址

using System.Net;
String hostInfo =Dns.GetHostName();//获取本机的计算机名
this.ComputerTextBox.Text = hostInfo;
System.Net.IPAddress addr;
addr = new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address); 
String IPAddress = addr.ToString();//获取本机的IP地址          
 this.ipTextBox.Text = IPAddress;


你可能感兴趣的:(C#)