看板 C_Sharp 關於我們 聯絡資訊
想試試抓client的ip來做一些保護的動作 但是求神了一天還是試不出來 一直抓到防火牆的ip 先附上測試code private string GetIP() { string ip; string trueIP = string.Empty; //先取得是否有經過代理伺服器 ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(ip)) { //沒經過代理伺服器,直接使用 ServerVariables["REMOTE_ADDR"] //並經過 CheckIP( ) 的驗證 trueIP = CheckIP(Request.ServerVariables["REMOTE_ADDR"]) ? Request.ServerVariables["REMOTE_ADDR"] : ""; } return trueIP; } /// <summary> /// 檢查 IP 是否合法 /// </summary> /// <param name="strPattern">需檢測的 IP</param> /// <returns>true:合法 false:不合法</returns> private bool CheckIP(string strPattern) { // 繼承自:System.Text.RegularExpressions // regular: ^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$ Regex regex = new Regex("^\\d{1,3}[\\.]\\d{1,3}[\\.]\\d{1,3}[\\.]\\d{1,3}$"); Match m = regex.Match(strPattern); return m.Success; } 抓到的都是防火牆的ip 無法抓到client的固定ip 是不是防火牆有一些設定 會轉址還是其他動作 硬體小弟真的是外行 麻煩大家指引一個方向 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.120.119.244 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1461829979.A.D2C.html
sosokill: 要抓外網IP? 04/28 21:18
sosokill: 喔 又是你 我還是不要發言好了 等等又被你酸 04/28 21:31