How do you get the IP address of the web/application server in .Net? Not the client IP address, but the server.
Just found something about Server Variables Here
How do you get the IP address of the web/application server in .Net? Not the client IP address, but the server.
Just found something about Server Variables Here
There are services that tell you what your external IP address is, but it might be subject to change.
Sample Services:
You probably want something like the following code, to get all IP addresses of the current machine. However it won't tell you which network adaptor (and thus IP address) a particular request came in on, if you have more than one.
String strHostName = Dns.GetHostName();
Console.WriteLine("Host Name: " + strHostName);
// Find host by name
IPHostEntry iphostentry = Dns.GetHostByName(strHostName);
// Enumerate IP addresses
foreach(IPAddress ipaddress in iphostentry.AddressList)
{
Console.WriteLine(ipaddress.ToString());
}
To get my own IP address in C#
IPHostEntry ipEntry = DNS.GetHostByName (Dns.GetHostName());
IPAddress [] addr = ipEntry.AddressList;
To get for other's machine
IPHostEntry ipEntry = DNS.GetHostByName (strHostName);
IPAddress [] addr = ipEntry.AddressList;
To get the IP address (and Coutnry/location) of a server programatically I use Utrace.de API. It returns an XML with IP address and location information too.
Example query: http://xml.utrace.de/?query=google.com