I already tried this method too....It's too returning server ip only... but when we test from our local system it returns our ip but if we deployed in server means it returns server ip only.... so that we decided to get client ip address using javascript...
You can capture the Ip Address like this:
HttpRequest currentRequest = HttpContext.Current.Request;
string ipAddress = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress == null || ipAddress.ToLower() == "unknown")
ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"];
return ipAddress;
asureshkumar...
Member
301 Points
75 Posts
How to get client ip address?
Mar 14, 2012 05:03 AM|LINK
Dear All,
I'm struggling to get client Ip from my webpage. I tried several methods but i get only server ip or proxy ip only...
Kindly suggest us how to get exact client ip using javascript or anyone else???????
A. Suresh Kumar
dinesh kumar...
Participant
986 Points
247 Posts
Re: How to get client ip address?
Mar 14, 2012 05:05 AM|LINK
String ipAddress =
System.Web.HttpContext.Current.Request.UserHostAddress;
Jai Jagannath
asureshkumar...
Member
301 Points
75 Posts
Re: How to get client ip address?
Mar 14, 2012 05:06 AM|LINK
Thx for you reply dinesh.....
I tried this too...but it returns server ip not client ip...
A. Suresh Kumar
dinesh kumar...
Participant
986 Points
247 Posts
Re: How to get client ip address?
Mar 14, 2012 05:15 AM|LINK
Then try this
string visitorIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (String.IsNullOrEmpty(visitorIPAddress))
visitorIPAddress = Request.ServerVariables["REMOTE_ADDR"];
if (string.IsNullOrEmpty(visitorIPAddress))
visitorIPAddress = Request.UserHostAddress;
Jai Jagannath
rakeshreddym
Member
299 Points
79 Posts
Re: How to get client ip address?
Mar 14, 2012 05:20 AM|LINK
Hi, use JSON this will help u
$.getJSON("http://jsonip.appspot.com?callback=?",
function(data){
alert( "Your ip: " + data.ip);
});
asureshkumar...
Member
301 Points
75 Posts
Re: How to get client ip address?
Mar 14, 2012 05:20 AM|LINK
Oh my dear....
I already tried this method too....It's too returning server ip only... but when we test from our local system it returns our ip but if we deployed in server means it returns server ip only.... so that we decided to get client ip address using javascript...
A. Suresh Kumar
rakeshreddym
Member
299 Points
79 Posts
Re: How to get client ip address?
Mar 14, 2012 05:23 AM|LINK
In asp.net like this
You can capture the Ip Address like this: HttpRequest currentRequest = HttpContext.Current.Request; string ipAddress = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (ipAddress == null || ipAddress.ToLower() == "unknown") ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"]; return ipAddress;sujithkumar
Contributor
3026 Points
564 Posts
Re: How to get client ip address?
Mar 14, 2012 05:48 AM|LINK
hi,
i think you will always get server address only..
please refer this link
http://bytes.com/topic/asp-net/answers/848515-how-get-client-ip-address-assigned-isp
amit.jain
Star
11225 Points
1815 Posts
Re: How to get client ip address?
Mar 14, 2012 07:40 AM|LINK
refer http://csharpdotnetfreak.blogspot.com/2008/12/finding-ip-address-behind-proxy-using-c.html
amiT jaiN
ASP.NET C# VB Articles And Code Examples
FightAsABull
Contributor
2228 Points
424 Posts
Re: How to get client ip address?
Mar 15, 2012 08:03 AM|LINK
Hi, I tried the following method:
String ipAddress =
System.Web.HttpContext.Current.Request.UserHostAddress;
and found it works.