How to get the Client Machine IP Address if Using Proxy
-
How to get the Client Machine IP Address if Using Proxy and also not. I Tried the following code, but all the code is returning 127.0.0.1. 1) TextBox1.Text = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 2) if (Context.Request.ServerVariables["HTTP_VIA"] != null) // using proxy { TextBox1.Text = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP. } else// not using proxy or can't get the Client IP { TextBox1.Text = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); } 3) TextBox1.Text = HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]; 4) TextBox1.Text = HttpContext.Current.Request.UserHostAddress.ToString();
-
How to get the Client Machine IP Address if Using Proxy and also not. I Tried the following code, but all the code is returning 127.0.0.1. 1) TextBox1.Text = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 2) if (Context.Request.ServerVariables["HTTP_VIA"] != null) // using proxy { TextBox1.Text = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP. } else// not using proxy or can't get the Client IP { TextBox1.Text = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); } 3) TextBox1.Text = HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]; 4) TextBox1.Text = HttpContext.Current.Request.UserHostAddress.ToString();
Hi dear, just try this using System.Net; and code : String strHostName, IPadd; strHostName = Dns.GetHostName(); IPAddress[] addr = Dns.GetHostAddresses(strHostName); IPadd = addr[0].ToString();
-
Hi dear, just try this using System.Net; and code : String strHostName, IPadd; strHostName = Dns.GetHostName(); IPAddress[] addr = Dns.GetHostAddresses(strHostName); IPadd = addr[0].ToString();
-
I think you are running this with http://localhost/... if upload in some live server System.Web.HttpContext.Current.Request.UserHostAddress should work... -------------------- logiclabz