-3

I've been trying for hours now to find a library or try to do it with java-core.

I'm trying to convert Expanded IPv6 to IPv4 but none of the googled methods does not work.

Also tried this library. https://github.com/seancfoley/IPAddress

Without much success.

Is it even possible?

To understand what I mean. For example, if you Google what is my ip, then Google will show you your IP in the Expanded IPv6 format.

Or you can look at this site: https://whatismyipaddress.com

How can the string (IPv6 long format) be converted to IPv4 in java?

18
  • 2
    What makes you think that is even possible? IPv6 and IPv4 addresses are different things. Commented Sep 18, 2023 at 7:44
  • The fact, that it should be simple and I cannot find the solution. Commented Sep 18, 2023 at 7:49
  • 2
    Ipv6 and ipv4 are two totally different things. You cannot convert one into the other Commented Sep 18, 2023 at 7:50
  • 4
    "it should be simple" - citation needed. Commented Sep 18, 2023 at 7:51
  • 1
    @Reilas, that library seems woefully out of date. It even includes Site-Local addresses that were deprecated in favor of ULA: "Site-local addresses are now deprecated as defined in [SLDEP]," but there is nothing to check for ULA. It does include IPv4-Mapped addresses: "In InetAddress and Inet6Address, it is used for internal representation; it has no functional role. Java will never return an IPv4-mapped address. These classes can take an IPv4-mapped address as input, both in byte array and text representation. However, it will be converted into an IPv4 address." Commented Sep 18, 2023 at 23:41

1 Answer 1

2

You can't convert IPv4 to IPv6, or the other way around. They are completely different things. It's like converting a telephone number to a street address: There may be come cases where there's a 1:1 mapping, or a 1:n mapping, but there's no guarantee.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, but from my small knowledge it should be convertable.
Then I'm sorry but your small knowledge is wrong ;-). If you can post some more details about why you think it's possible, we might be able to explain more.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.