Tuesday, August 17, 2010

Get Server's IP address

how to get server's IP address ?????
generally Request methods will return localhost or 127.0.0.1

to get global IP address:


string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();

Taken from blog posts @(http://forums.asp.net/p/892765/2167498.aspx)

Note :
System.Net.Dns.GetHostAddresses will return list of address that machine uses,
if machine uses more network interface this value can be differ what you want to take..(IPv6 e.g) this time you can eliminate HostAddreses with type..

No comments: