views:

51

answers:

4

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

A: 

There are services that tell you what your external IP address is, but it might be subject to change.

Sample Services:

McKay
+2  A: 

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());
   }
NeilDurant
+1  A: 

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;
Ankit Jain
A: 

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

Ankit Jain
I think he's looking for discovering the IP address of his current server, and doesn't know how to get data to pass to utrace.de
McKay
ooh.. I got it. i should have given example of domain name.. rather than IP.
Ankit Jain