gpt4 book ai didi

c# - C#中IPv6到IPv4相互转换

转载 作者:太空狗 更新时间:2023-10-29 22:34:49 25 4
gpt4 key购买 nike

我有一个 IPv4 格式的 IP 列表,它是从我的网络服务器收到的以前的 HttpRequest 对象中收集的。我有一个 java applet,它以 Ipv6 格式提供 IP 地址(java applet 返回一堆数据以及 IP 地址)。我需要检查小程序返回的 IP 是否与列表中的任何项目匹配。

如何相互转换 IPv6 和 IPv4 格式?

我的 Web 应用程序是基于 ASP.Net C# 构建的

编辑

这是我面临的问题。 Java 小程序从客户端返回一堆 IP,我假设这取决于客户端机器拥有的网卡数量。

除此之外,我还从 ASP.Net HTTPRequest 对象获得了一个 IP 地址。我需要找出哪个 IP 实际用于连接到我的网站并执行一些任务。

问题是有时我只能从 javaapplet 获得一个 IPv6 格式的 IP,而我从 HTTPRequest 对象获得的 IP 是 IPv4 格式,所以比较失败。

最佳答案

您在谈论 IPv4-IPv6 映射或 IPv4 地址嵌入。

IPv4 address embedding is used to create a relationship between an IPv4 address and an IPv6 address to aid in the transition from IPv4 to IPv6. One type, the IPv4-compatible IPv6 address, is used for devices that are compatible with both IPv4 and IPv6; it begins with 96 zero bits. The other, the IPv4-mapped address, is used for mapping IPv4 devices that are not compatible with IPv6 into the IPv6 address space; it begins with 80 zeroes followed by 16 ones.

..

The difference between these two kinds of addresses is subtle, but important. The first 80 bits are always zero, so when this is seen you know it is an embedded IPv4 address of some sort. IPv4-compatible IPv6 addresses are only used for devices that are actually IPv6-aware; the IPv4-compatible address is in addition to its conventional IPv6 address. In contrast, if the "FFFF" is seen for the 16 bits after the initial 80, this designates a conventional IPv4 devices whose IPv4 address has been mapped into the IPv6 format. It is not an IPv6-capable device.

所以底线是,除非它们映射在一起,否则您将无法相互转换。你需要一个 translator .

关于c# - C#中IPv6到IPv4相互转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3568971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com