jyothis
jyothis

Reputation: 84

Get Client machine's Exact IP Address(Not public IP) using Asp/Javascript

is there any way to get client machines exact ip address in asp.net.I have tried following code

System.Web.HttpContext context = System.Web.HttpContext.Current;
string ipAddress =context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];


        if (!string.IsNullOrEmpty(ipAddress))
        {
            string[] addresses = ipAddress.Split(',');
            if (addresses.Length != 0)
            {
                return addresses[0];
            }
        }

        return context.Request.ServerVariables["REMOTE_ADDR"];

But this code sometimes returns exact ip address of machine and sometimes it gives public ip address,how to solve this issue

Upvotes: 0

Views: 242

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86754

You cannot get a client machine's address if it is behind a NAT firewall. Such an address would be meaningless anyway as many clients could have the same address.

Upvotes: 4

Related Questions