如何获取本机和外面IP地址
偶是新手,希望GG和JJ们说的详细点,谢谢了!
using System.Net;
using System.Net.Sockets;
private void button1_Click(object sender, System.EventArgs e)
{
//获取本地主机名称
string host=Dns.GetHostName();
this.label1.Text=host;
IPHostEntry ipHostEntry=Dns.GetHostByName(Dns.GetHostName());
//获得本机IP地址
IPAddress addr = new IPAddress ( ipHostEntry.AddressList [0].Address ) ;
this.label2.Text=addr.ToString();
}