移动联通网络ip奇怪问题
测试代码:
<form id="form1" runat="server"> 您的IP地址是:[<asp:Label ID="lblIP" runat="server"></asp:Label>] <br /> IP地址:<asp:TextBox ID="txtIP" runat="server" Width="300"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="IP错误" Display="Dynamic" ControlToValidate="txtIP" ValidationExpression="^\s*((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\s*$"></asp:RegularExpressionValidator> <asp:Button ID="btnQuery" runat="server" Text="查询IP" OnClick="btnQuery_Click" /> <br /> 查询IP地区: <asp:Label ID="lblRegion" runat="server" ForeColor="red"></asp:Label> <asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible="false"> <h2>ip信息1</h2> <div> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </div> <h2>ip信息2</h2> <div> <asp:Literal ID="Literal2" runat="server"></asp:Literal> </div> <h2>ip信息3</h2> <div> <asp:Literal ID="Literal3" runat="server"></asp:Literal> </div> <h2>ip信息4</h2> <div> <asp:Literal ID="Literal4" runat="server"></asp:Literal> </div> </asp:PlaceHolder> </form>
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.lblIP.Text = Request.UserHostAddress; this.txtIP.Text = Get("ip"); if (this.txtIP.Text.Trim() != "") { this.Validate(); btnQuery_Click(sender, e); } string t = Get("t"); if (!string.IsNullOrEmpty(t)) { this.PlaceHolder1.Visible = true; string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (!string.IsNullOrEmpty(ip)) { new LogForError().AddLogForError("HTTP_X_FORWARDED_FOR", 1, ip); this.Literal1.Text += "HTTP_X_FORWARDED_FOR:" + ip + "<br/>"; this.Literal2.Text += "HTTP_X_FORWARDED_FOR:" + GetIp1(ip) + "<br/>"; this.Literal3.Text += "HTTP_X_FORWARDED_FOR:" + GetIp2(ip) + "<br/>"; this.Literal4.Text += "HTTP_X_FORWARDED_FOR:" + GetIp3(ip) + "<br/>"; } ip = Request.ServerVariables["REMOTE_ADDR"]; if (!string.IsNullOrEmpty(ip)) { new LogForError().AddLogForError("REMOTE_ADDR", 1, ip); this.Literal1.Text += "REMOTE_ADDR:" + ip + "<br/>"; this.Literal2.Text += "REMOTE_ADDR:" + GetIp1(ip) + "<br/>"; this.Literal3.Text += "REMOTE_ADDR:" + GetIp2(ip) + "<br/>"; this.Literal4.Text += "REMOTE_ADDR:" + GetIp3(ip) + "<br/>"; } ip = new IP().GetIPAddress(); if (!string.IsNullOrEmpty(ip)) { new LogForError().AddLogForError("CommonClass", 1, ip); this.Literal1.Text += "CommonClass:" + ip + "<br/>"; this.Literal2.Text += "CommonClass:" + GetIp1(ip) + "<br/>"; this.Literal3.Text += "CommonClass:" + GetIp2(ip) + "<br/>"; this.Literal4.Text += "CommonClass:" + GetIp3(ip) + "<br/>"; } } } } private string GetIp1(string ip) { return "<span>" + ip.Replace(".", ".</span><span>") + "</span>"; } private string GetIp2(string ip) { return "<span>-" + ip.Replace(".", "</span><span>-") + "</span>"; } private string GetIp3(string ip) { return ip.Replace(".", " . "); } protected void btnQuery_Click(object sender, EventArgs e) { if (!this.IsValid) { ShowMessageBox("验证失败!"); return; } if (this.txtIP.Text.Trim() != "") { this.lblRegion.Text = new IP().GetAreaString(this.txtIP.Text.Trim()); } }
有部分客户打开页面时这样的,几处ip信息不一样:
数据日志记录的信息:
总结:返回到客户端页面不进行处理的ip,会被替换掉其他ip。“27.24.190.111”被替换成了“202.114.0.111”
难道是代理服务器干的?还是移动联通干的?
各位有遇到过?