2014年1月26日 星期日

[.NET] 取得Server或Client IP

1. 取得Server IP語法:
using System.Net;
IPAddress ServerIP = IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address);
Response.Write("Server IP=" + ServerIP.ToString());

2. 取得Client IP
string strClientIP = Request.ServerVariables["REMOTE_ADDR"].ToString();
string strClientIP = Request.UserHostAddress;
//使用代理伺服器
string strClientIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();



參考資料:
http://blog.xuite.net/sunnysoap/r/25283108-C%23+%E5%A6%82%E4%BD%95%E5%8F%96%E5%BE%97%E6%9C%AC%E6%A9%9F(Server)%E7%9A%84IP
http://www.dotblogs.com.tw/jimmyyu/archive/2009/05/21/8493.aspx


http://bytes.com/topic/asp-net/answers/848515-how-get-client-ip-address-assigned-isp
http://dotnetstock.com/technical/how-to-get-ip-address-of-a-client-system-using-asp-net
http://csharpdotnetfreak.blogspot.com/2008/12/finding-ip-address-behind-proxy-using-c.html
http://forums.asp.net/t/1780050.aspx

沒有留言:

張貼留言