Ever Wanted to Own and Operate a Fully Featured
Dynamic DNS Service?
Now You Can With MintDNS 2009 Enterprise - - Our
Award Winning Dynamic DNS (DDNS) Server Suite!!!
It's never been easier to run your own DDNS service.
Looking for free Dynamic DNS (DDNS) services? Please use our free DDNS
service at
http://www.dynddns.us
MintDNS Knowledge Base
Go Back
HTTP_X_FORWARDED_FOR can sometimes return a comma delimited list of IP
addresses. Please feel free to use this code in any way you like.
Example IP's 24.116.98.21, 24.116.98.23, 24.113.65.23 The first IP in list should be the correct IP for the user. The last IP should be the address of the Proxy. I have included code samples for both options. Classic ASP example. (Correctly detecting a users IP)
VBScript Code:
MyIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If MyIP = "" or Trim(LCase(MyIP)) = "unknown" Then MyIP = Request.ServerVariables("REMOTE_ADDR") End If IsMulti = InStr(1, MyIP, ",", 1) 'Use one or the other not both 'Gets the first IP in list If IsMulti > 0 Then strArray = Split(MyIP, ",") MyIP = strArray(0) MyIP = Trim(MyIP) End If 'Gets the last IP in list If IsMulti > 0 Then strArray = Split(MyIP, ",") For iCntr = 0 To UBound(strArray) MyIP = strArray(iCntr) Next MyIP = Trim(MyIP) End If In C# (This sample gets the first IP in the list)
C# Code:
String MyIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
//Trim and lowercase IP if not null if (MyIP != null) { MyIP = MyIP.ToLower(); MyIP = MyIP.Trim(); } //If IP is null use different detection method. Else pull the correct IP from list. if ((MyIP == null) || (MyIP == "unknown")) { MyIP = Request.ServerVariables["REMOTE_ADDR"]; } else if (MyIP.IndexOf(",") != -1){ string[] IPs = MyIP.Split(','); MyIP = IPs.GetValue(0).ToString().Trim(); } As always if you need any help, please feel free to ask. |
Go Back