I am working on an application that redirects the user to closest server automatically (there are multiple servers). For that I need to detect client's IP address and server's IP address the client is visiting. I think to get the client's IP address I can use:
HttpContext.Current.Request.UserHostAddress
How do I get the server's IP address that the client is visiting? Is it possible to detect it without using DNS querying ?
Looks like it's here:
Getting the IP address of server in ASP.NET?
//this gets the ip address of the server pc
public string GetIPAddress()
{
string strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
return ipAddress.ToString();
}
Kudos to TStamper!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With