Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Client's and Server's IP address

Tags:

c#

asp.net

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 ?

like image 576
skos Avatar asked Nov 14 '22 08:11

skos


1 Answers

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!

like image 120
RemarkLima Avatar answered Nov 16 '22 04:11

RemarkLima