Below is my code, when I run in local, it can successfully return my public IP address. But when I host the website to the server, it always returns server public IP address. Does anyone know what is the root cause? I wish to get the public IP address from my client who is using the page I created.
static string GetPublicIPAddress()
{ string address = ""; try { WebRequest request = WebRequest.Create("https://bot.whatismyipaddress.com"); using (WebResponse response = request.GetResponse()) using (StreamReader stream = new StreamReader(response.GetResponseStream())) { address = stream.ReadToEnd(); }
}
catch(Exception ex) {
address = ex.Message;
}
return address;
}