Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good morning to all.

I am trying to get the IP of the client with:
C#
Request.ServerVariables["REMOTE_HOST"] 
//or
Request.ServerVariables["REMOTE_ADDR"]

but I getting something like this:
REMOTE_ADDR = fc80::ad57:e86c:acc7:7779%10

I am assuming that it is encoded somehow Hex.
How can I translate that to the real IP or get the IP directly??

That was my original question, I have been getting routines here and there on the internet and none is capable to get a meaninful address like 127.0.0.1 or the like.

Anyone has a better idea?

For whatever is worth,
I just found that the fc80::ad57:e86c:acc7:7779%10 corresponds to the "Link-local IPv6 Address" specified in the network adapter properties detail in Windows 7. How can I get the IPv4 address??

TIA
Pete
Posted
Updated 3-Mar-11 5:40am
v6

 
Share this answer
 
Here is my Generic Utility for IP:
C#
/// <summary>
/// Get the current user (client) IP address
/// </summary>
/// <returns>IP address as a readable string</returns>
public static string GetUserIPAddress()
    {
    Page page = HttpContext.Current.Handler as Page;
    string ip = page.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (!string.IsNullOrEmpty(ip))
        {
        string[] ipRange = ip.Split(',');
        ip = ipRange[0];
        }
    else
        {
        ip = page.Request.ServerVariables["REMOTE_ADDR"];
        }
    return ip.Trim();
    }
 
Share this answer
 
Comments
pedroestrada 12-Feb-11 4:53am    
Thanks for the routine, I just tried it, unfortunatelly still returns fc80::ad57:e86c:acc7:7779%10
Hope IpAddress[^] may give you an clear idea.
 
Share this answer
 
Did you try
Request.UserHostAddress
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900