Hi i'm working on logging on a security website in school, but it's all localhost based.
I'm looking to actually capture whoever visits my website. I actually want to capture the external IP address of whomever machine the person is using. For example, when i run my website and hit a button it immediately captures my external ip address.
To be frank, i have no much knowledge in this area of ip address but i have sufficient understanding on what are things like client, server, ip address, port numbers, etc.. which i learnt in my networking modules.
To give more information, when you visit website to check IP address or any other what is your ip website, you get your external ip address. I actually want to capture this IP address and save it into my database.
I did do my research on stackoverflow, codeproject, whichever that i could find help from, but it always return either ::1, which i pressume is 127.0.0.1 our default localhost address?
I have tried all these down below to experiment what they produce..
protected void getIP_Click(object sender, EventArgs e)
{
String hostName = System.Net.Dns.GetHostName();
String clientIpAddressHostName = System.Net.Dns.GetHostAddresses(hostName).GetValue(0).ToString();
IP1.Text = clientIpAddressHostName;
String clientIpAddress = HttpContext.Current.Request.ServerVariables["REMOTE_HOST"].ToString();
IP2.Text = clientIpAddress;
String ip = null;
if (String.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]))
{
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
IP3.Text = ip;
String ipNext = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
IP4.Text = ipNext;
String ipNextNext = HttpContext.Current.Request.UserHostAddress;
IP5.Text = ipNextNext;
String last = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.GetValue(0).ToString();
IP6.Text = last;
}
I also read online that i can actually get my external ip address from an external source from a website based on this answer down below from stackoverflow
But i havent tried it, as i assume this isn't a safe way for doing? Please correct me if i'm wrong..
Still cant get what im looking for after searching high and low..
Could anyone please assist? Would appreciate any help!