Jonny Piazzi
Jonny Piazzi

Reputation: 3784

Get Server Machine IP

In a Asp.Net MVC4 Aplication, How I get the IP of my server, in other words the IP of the machine where my aplication is running in IIS?

Why I need This?
I'm working in a project that will be published in a server with a load balance. But there is a background thread that execute some stuff and I need to guarantee that this thread will be executed only in a single server. The only information that I have about the servers is the IP of each one. (Other information is classified for security reasons).

Upvotes: 0

Views: 2550

Answers (1)

Miulx
Miulx

Reputation: 61

try this:

string hostName = System.Net.Dns.GetHostName();
string ipAddress = System.Net.Dns.GetHostEntry(hostName).AddressList[index].ToString();

index is the index of network connection at your server.

Upvotes: 1

Related Questions