protected string GetIP() //获取本地IP
{
IPHostEntry ipHost = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddr = ipHost.AddressList[0];
return ipAddr.ToString();
}
string hostname = System.Net.Dns.GetHostName(); //主机
System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostname);//网卡IP地址集合
string IP = ipEntry.AddressList[0].ToString();//取一个IP
//读取IP信息
IPHostEntry myIP = Dns.GetHostByName(Dns.GetHostName());
txtIP.Text = myIP.AddressList.GetValue(0).ToString();
public static string GetIpAddress()
{
IPAddress[] hostipspool = Dns.GetHostAddresses("");
if (hostipspool.Length > 0)
return hostipspool[0].ToString();//本机的局域网IP地址
else
return "can't get ip address.";
}
用这个就能实现:string IP = Request.UserHostAddress;
你写到load加载事件里:
然后输入一下看看