I have written the following code to get the IPv4 address of my machine. When we deploy this code on the server, this code gives me the IP address of the server, but not the machines IP on which application running?
public string getIpAddress()
{
try
{
string myHost = System.Net.Dns.GetHostName();
string myIP = null;
for (int i = 0; i <= System.Net.Dns.GetHostEntry(myHost).AddressList.Length - 1; i++)
{
if (System.Net.Dns.GetHostEntry(myHost).AddressList[i].IsIPv6LinkLocal == false)
{
myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[i].ToString();
}
}
return myIP;
}
catch (Exception)
{
throw;
}
}