做一個 查詢標識的系統,竄貨 需要 用查詢的IP 和 貨物的流向地進行匹配。 問題是這樣子的,用電腦測試 IP獲取都是準確的。 我知道 IP都是隨機分配的,但是 聯通是聯通 電信是電信,網段還是固定在一個範圍內的。
但是 我用手機去訪問獲取IP的時候 居然出現了 聯通手機顯示 電信的網段。很是糾結。 最後 用 string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 去獲取代理商的IP 即可。但是這樣獲取
危險很大。 百度介紹很詳細
/string ip = Request.ServerVariables.Get("Remote_Addr");
//string ip = System.Web.HttpContext.Current.Request.UserHostAddress;
string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];