asp.net mvc 4 - Get ip address from a request mvc -


i'm trying ip address of device making request. should work in both self hosted or hosted on server internet access.

i've tried this:

//get visitor ip address method     public string getvisitoripaddress()     {         string stringipaddress;         stringipaddress = request.servervariables["http_x_forwarded_for"];          if (stringipaddress == null) //may http_x_forwarded_for null             stringipaddress = request.servervariables["remote_addr"]; //we can use remote_addr         else if (stringipaddress == null)             stringipaddress = getlanipaddress();          return stringipaddress;     }      //get lan connected ip address method     public string getlanipaddress()     {         //get host name         string stringhostname = dns.gethostname();         //get ip host entry         iphostentry iphostentries = dns.gethostentry(stringhostname);         //get ip address ip host entry address list         system.net.ipaddress[] arripaddress = iphostentries.addresslist;         return arripaddress[arripaddress.length - 1].tostring();     } 

but in both cases get: "::1".

what doing wrong?

in ipv6 ::1 same 127.0.0.1 in ipv4. when run local machine should getting.

you can try modify hosts file, or try access application it's ip http://192.168.0.1 (for example).


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -