i am using an service to get client country based on the ip address but it is made through web api rest service when i used UserHostAddress it shows internal ip only when i send this to service it is showing wrong country is there any solution to get country or ipaddresss
Asked
Active
Viewed 1,034 times
0
-
I'm not sure what you are asking. Did you call the server from an internal IP? `UserHostAddress` displays the IP that the server sees. If the client is behind a NAT firewall, this will be the "public" IP. Otherwise, it's the client's actual IP. The server doesn't know nor care what that address is. – Panagiotis Kanavos Apr 29 '14 at 09:22
-
possible duplicate of [UserHostAddress gives wrong IPs](http://stackoverflow.com/questions/200527/userhostaddress-gives-wrong-ips) – Panagiotis Kanavos Apr 29 '14 at 09:24
-
Can you try, `string SourceIP = String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) ? Request.ServerVariables["REMOTE_ADDR"] : Request.ServerVariables["HTTP_X_FORWARDED_FOR"];` – Akash Kava Apr 29 '14 at 09:26
1 Answers
0
If you have local ip, and your router has the real one, your computer only communicates with router, and router communicates with Internet. There are two ways of getting routers IP:
- Send http request to some site that shows your IP and get it from there.
- Connect to router interface and get IP directly from router.

Flash Thunder
- 11,672
- 8
- 47
- 91