Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem Converting ipv6 to ipv4

Tags:

c#

asp.net

ipv6

I have some code in an asp.net app that needsto get the ipv4 address of the client computer (the users are all on our own network). Recently we upgraded the server the app runs on to windows 2008 server. Now the Request.UserHostAddress code returns the ipv4 when the client is on an older OS and ipv6 when they are on a newer OS (Vista and higher). So the feature that relys on this works for some clients and not others.

I added code that is supposed to convert from ipv6 to ipv4 to try to fix this problem. It's from this online tutorial: http://www.4guysfromrolla.com/articles/071807-1.aspx .I'm using dsn.GetHostAddress and then looping through the IPs returned looking for one that is "InterNetwork"

foreach (IPAddress IPA in Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress))
{
    if (IPA.AddressFamily.ToString() == "InterNetwork")
    {
        IP4Address = IPA.ToString();
        break;
    }
}

if (IP4Address != String.Empty)
{
    return IP4Address;
}


foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
{
    if (IPA.AddressFamily.ToString() == "InterNetwork")
    {
        IP4Address = IPA.ToString();
        break;
    }
}

return IP4Address;

The problem is that this isn't working for me. The clients connecting from ipv4 continue to return the correct ipv4 IP of the client computer, but the clients connecting from Vista and Windows 7 it is returning the ipv4 IP of the SERVER machine not the client computer.

like image 897
Eden Avatar asked Jan 11 '10 18:01

Eden


People also ask

Is it possible to convert IPv6 to IPv4?

Not all IPv6 address can be converted to IPv4. You can only convert valid IPv4 represented IPv6 addresses. These addresses can be in either 6to4 notation or IPv4-mapped notation.

Why is the transition from IPv6 to IPv4 happening?

RFC 1933 defines the transition tools currently available. The rationale for transition is either the lack of IPv4 address space or the required use of new features in IPv6, or both. The IPv6 specification requires 100 per cent compatibility for the existing protocols.

What are the challenges shifting from IPv4 to IPv6?

Difficulty in detecting and managing unknown or unauthorized IPv6 assets on existing IPv4 production networks. The added complexity of operating parallel IPv4 and IPv6 networks. A lack of IPv6 maturity in security products. The proliferation of IPv6 and IPv4 tunnels can complicate defenses.

Does IPv6 conflict with IPv4?

Actually, IPv4 and IPv6 aren't compatible with each other, which means devices cannot communicate directly. Today, IPv4 is still dominant in IP network, while IPv6 network has only a small range of deployment and commercial use.


1 Answers

Simple answer: Disable IPV6 on the server, or remove the IPV6 address of the server from the DNS entry.

There is not a magic IPV4<->IPV6 converter. They're completely different protocols, and addresses in one don't translate to the other. If you want to reliably retrieve the IPV4 address of the client, you need to make sure that the client connects over IPV4.

like image 68
Jesse Weigert Avatar answered Oct 19 '22 08:10

Jesse Weigert