0
var result = GetUser_IP(); protected string GetUser_IP() { string ipList = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (!string.IsNullOrEmpty(ipList)) { return ipList.Split(',')[0]; } return Request.ServerVariables["REMOTE_ADDR"]; } 

result always displays ::1 why can I not see IP address instead of ::1

Also what is ::1 for a IP address result ?

What I miss in code, how can I get my IP address like in http://whatismyipaddress.com/ ?

Any help will be appreciated.

Thanks.

2 Answers 2

2

Yes ::1 is a IP Address of localhost. When ever you will run your application using visual studio it will provide you a IP address is of localhost.

::1 is the loopback address in IPv6. Think of it as the IPv6 version of 127.0.0.1.

Sign up to request clarification or add additional context in comments.

4 Comments

I want some users to access of management page in my code in local . How can i do this ? I do not want everyone to access to page
Use username and password.
@Soner — The way you are doing already. You just need to have your network configured so the traffic comes from the IP address you care about. (This is not something you should worry about when accessing via localhost).
When i publish my project and load to server you mean it will be worked.. If it is I will do this way i am trusting you :)
0

use below method

public static string GetVisitorIPAddress(HttpContext _context) { bool GetLan = true; string visitorIPAddress = _context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (String.IsNullOrEmpty(visitorIPAddress)) visitorIPAddress = _context.Request.ServerVariables["REMOTE_ADDR"]; if (string.IsNullOrEmpty(visitorIPAddress)) visitorIPAddress = _context.Request.UserHostAddress; if (string.IsNullOrEmpty(visitorIPAddress) || visitorIPAddress.Trim() == "::1") { GetLan = true; visitorIPAddress = string.Empty; } if (GetLan) { if (string.IsNullOrEmpty(visitorIPAddress)) { //This is for Local(LAN) Connected ID Address string stringHostName = Dns.GetHostName(); //Get Ip Host Entry IPHostEntry ipHostEntries = Dns.GetHostEntry(stringHostName); //Get Ip Address From The Ip Host Entry Address List System.Net.IPAddress[] arrIpAddress = ipHostEntries.AddressList; try { visitorIPAddress = arrIpAddress[arrIpAddress.Length - 0].ToString(); } catch { try { visitorIPAddress = arrIpAddress[0].ToString(); } catch { try { arrIpAddress = Dns.GetHostAddresses(stringHostName); visitorIPAddress = arrIpAddress[0].ToString(); } catch { visitorIPAddress = "127.0.0.1"; } } } } } return visitorIPAddress; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.