怎么获取IP地址
每个人浏览网页时,但要怎么获取他的IP地址 --------------------编程问答-------------------- Request.ServerVariables("REMOTE_ADDR") --------------------编程问答-------------------- public string GetServicesIP(){//
IPHostEntry IPHost = Dns.GetHostByName(Dns.GetHostName());
IPAddress[] addr = IPHost.AddressList;
return addr[0].ToString().Trim();
} --------------------编程问答-------------------- 外面用个 ip = this.GetServicesIP();获取下
记得using System.Net; --------------------编程问答-------------------- 来迟了 --------------------编程问答-------------------- Request.ServerVariables("REMOTE_ADDR")
在asp里用吧,后面那个没用过 --------------------编程问答-------------------- 用Request.ServerVariables加上特定的参数 --------------------编程问答-------------------- Public Function func_GetIP() As String
Dim mso As ManagementObjectSearcher = New ManagementObjectSearcher("select * from Win32_NetworkAdapterConfiguration where IPEnabled='TRUE'")
Dim ip As String = String.Empty
For Each mo As ManagementObject In mso.Get()
If Not IsDBNull(mo("IPAddress")) Then
For Each str As String In mo("IPAddress")
ip += str
Next
End If
Next
Return ip
End Function --------------------编程问答-------------------- wenyiyi说的实在c/S模式下的获取方式 --------------------编程问答-------------------- 。。。。。BS好不。偶自己用过的 --------------------编程问答-------------------- c# string strIP = Request.ServerVariables.Get("REMOTE_ADDR");
--------------------编程问答-------------------- 顶下把、
--------------------编程问答-------------------- Request.UserHostAddress.ToString() --------------------编程问答-------------------- c# string strIP = Request.ServerVariables.Get( "REMOTE_ADDR "); --------------------编程问答-------------------- 又迟到了 --------------------编程问答-------------------- Request.UserHostAddress.ToString() --------------------编程问答-------------------- 谷歌一下就知道了 --------------------编程问答-------------------- public string getIpAddr()
{
string ip = HttpContext.Current.Request.Headers["x-forwarded-for"];
if (string.IsNullOrEmpty(ip) || "unknown".Equals(ip, StringComparison.InvariantCultureIgnoreCase))
{
ip = HttpContext.Current.Request.Headers["Proxy-Client-IP"];
}
if (string.IsNullOrEmpty(ip) || "unknown".Equals(ip, StringComparison.InvariantCultureIgnoreCase))
{
ip = HttpContext.Current.Request.Headers["WL-Proxy-Client-IP"];
}
if (string.IsNullOrEmpty(ip) || "unknown".Equals(ip, StringComparison.InvariantCultureIgnoreCase))
{
ip = HttpContext.Current.Request.UserHostAddress;
}
return ip;
} --------------------编程问答-------------------- 这么多正解了 --------------------编程问答--------------------
string ip = Request.UserHostAddress;--------------------编程问答-------------------- 谢谢,2,3楼的有用!
补充:.NET技术 , ASP.NET