Elena Elena - 1 year ago 162
ASP.NET (C#) Question

ASP.NET: get external IP address

I developed site. I need to get IP of site visitors.
I try to use Request, but it have only internal IP:


I looked all keys in Server Variables collection - the same result:

foreach (string var in Request.ServerVariables)

How can I get external IP address?

Answer Source

You can use it to get External (public) IP Address..

public static string getExternalIp()
            string externalIP;
            externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
            externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"))
            return externalIP;
        catch { return null; }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download