问题转换IPv6​​到IPv4 [英] Problem Converting ipv6 to ipv4

查看:240
本文介绍了问题转换IPv6​​到IPv4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在needsto获取客户端计算机的IPv4地址一个asp.net应用中的一些code(用户都是我们自己的网络上)。最近,我们升级了应用程序运行到Windows 2008 Server的服务器。现在Request.UserHostAddress code当客户端是在旧操作系统和IPv6时,他们在一个新的操作系统(Vista和更高版本)返回的IPv4。所以,在这个relys该功能适用​​于某些客户端,而不是别人。

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.

我添加code是应该从IPv6的转换为IPv4来尝试解决这个问题。这是一个从这个网上教程:<一href=\"http://www.4guysfromrolla.com/articles/071807-1.aspx\">http://www.4guysfromrolla.com/articles/071807-1.aspx .I'm使用dsn.GetHostAddress然后通过IP地址循环返回的寻找一个是网间

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;

问题是,这不是为我工作。从IPv4连接客户端继续返回客户端计算机的正确IP IPv4的,但是从Vista和Windows 7连接客户端则返回的服务器的机器不是客户端计算机的IPv4 IP地址。

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.

推荐答案

答案很简单:禁用IPV6在服务器上,或从DNS条目中删除服务器的IPv6地址。

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

有没有一个神奇的IPV4&LT; - > IPV6的转换器。它们是完全不同的协议,以及在一个地址不转换到另一个。如果要可靠地获取客户端的IPv4地址,您需要确保客户端连接通过IPv4。

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.

这篇关于问题转换IPv6​​到IPv4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆