using System.Net;
using System.Net.Sockets;
private void button1_Click(object sender, System.EventArgs e)
{
IPHostEntry ipHostEntry=Dns.GetHostByName(Dns.GetHostName());
//获得本机IP地址
IPAddress addr = new IPAddress ( ipHostEntry.AddressList [0].Address ) ;
this.label1_IP.Text=addr.ToString();
}