How to normalise IPv6 address in Java?Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Maximum length of the textual representation of an IPv6 address?Fastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java
Do my partner and son need an SSN to be dependents on my taxes?
Fibonacci sequence and other metallic sequences emerged in the form of fractions
How do I correctly reduce geometry on part of a mesh?
Using roof rails to set up hammock
writing a function between sets vertically
Would a 7805 5v regulator drain a 9v battery?
Right indicator flash-frequency has increased and rear-right bulb is out
How can I detect if I'm in a subshell?
...and then she held the gun
How is linear momentum conserved in circular motion?
I just entered the USA without passport control at Atlanta airport
Got a new frameset, don't know why I need this split ring collar?
Can a character with the Polearm Master feat make an opportunity attack against an invisible creature that enters their reach?
How to prevent cables getting intertwined
Co-worker is now managing my team. Does this mean that I'm being demoted?
Explicit song lyrics checker
Why we can't jump without bending our knees?
How "fast" do astronomical events occur?
Query nodes and attributes of parent ways
How to write a nice frame challenge?
How to make all magic-casting innate, but still rare?
A medieval book with a redhead girl as a main character who allies with vampires and werewolves against scientific opposition
how to find which software is doing ssh connection?
How can the US president give an order to a civilian?
How to normalise IPv6 address in Java?
Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Maximum length of the textual representation of an IPv6 address?Fastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Given a string which contains an IPv6 address in one of it's formats, is there a Java standart way to normalise it in a way that the same normalised value for different formats of the same address?
i.e
normalise("2001:db8:0:0:1:0:0:1") = x
normalise("2001:db8::1:0:0:1") = x
normalise("2001:db8:0:0:1::1") = x
java ip ipv6
add a comment |
Given a string which contains an IPv6 address in one of it's formats, is there a Java standart way to normalise it in a way that the same normalised value for different formats of the same address?
i.e
normalise("2001:db8:0:0:1:0:0:1") = x
normalise("2001:db8::1:0:0:1") = x
normalise("2001:db8:0:0:1::1") = x
java ip ipv6
add a comment |
Given a string which contains an IPv6 address in one of it's formats, is there a Java standart way to normalise it in a way that the same normalised value for different formats of the same address?
i.e
normalise("2001:db8:0:0:1:0:0:1") = x
normalise("2001:db8::1:0:0:1") = x
normalise("2001:db8:0:0:1::1") = x
java ip ipv6
Given a string which contains an IPv6 address in one of it's formats, is there a Java standart way to normalise it in a way that the same normalised value for different formats of the same address?
i.e
normalise("2001:db8:0:0:1:0:0:1") = x
normalise("2001:db8::1:0:0:1") = x
normalise("2001:db8:0:0:1::1") = x
java ip ipv6
java ip ipv6
edited Sep 7 '18 at 19:57
Thomas Fritsch
5,755122237
5,755122237
asked Sep 2 '18 at 8:10
ABRABR
4551720
4551720
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can achieve this easily
by parsing the string with InetAddress.getByName(String)
and then converting back to string with getHostAddress()
:
public static String normalize(String s) throws UnknownHostException
return InetAddress.getByName(s).getHostAddress();
This method returns "2001:db8:0:0:1:0:0:1"
for all your 3 examples.
By the way: The code above can normalize IPv6 and IPv4 addresses.
add a comment |
The open-source IPAddress Java library provides various methods for different string formats. Several can be used to produce a normalized string. Disclaimer: I am the project manager of the IPAddress library.
Two that are well-suited to be considered "standardized" strings are the canonical string and the normalized string.
The canonical string is the recommended way of writing IPv6 addresses as defined by RFC 5952
The normalized string is the format produced by the class java.net.InetAddress.
static void printNormalized(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toNormalizedString());
static void printCanonical(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toCanonicalString());
String strs[] =
"2001:db8:0:0:1:0:0:1",
"2001:db8::1:0:0:1",
"2001:db8:0:0:1::1";
printCanonical(strs);
System.out.println();
printNormalized(strs);
Output:
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52135144%2fhow-to-normalise-ipv6-address-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can achieve this easily
by parsing the string with InetAddress.getByName(String)
and then converting back to string with getHostAddress()
:
public static String normalize(String s) throws UnknownHostException
return InetAddress.getByName(s).getHostAddress();
This method returns "2001:db8:0:0:1:0:0:1"
for all your 3 examples.
By the way: The code above can normalize IPv6 and IPv4 addresses.
add a comment |
You can achieve this easily
by parsing the string with InetAddress.getByName(String)
and then converting back to string with getHostAddress()
:
public static String normalize(String s) throws UnknownHostException
return InetAddress.getByName(s).getHostAddress();
This method returns "2001:db8:0:0:1:0:0:1"
for all your 3 examples.
By the way: The code above can normalize IPv6 and IPv4 addresses.
add a comment |
You can achieve this easily
by parsing the string with InetAddress.getByName(String)
and then converting back to string with getHostAddress()
:
public static String normalize(String s) throws UnknownHostException
return InetAddress.getByName(s).getHostAddress();
This method returns "2001:db8:0:0:1:0:0:1"
for all your 3 examples.
By the way: The code above can normalize IPv6 and IPv4 addresses.
You can achieve this easily
by parsing the string with InetAddress.getByName(String)
and then converting back to string with getHostAddress()
:
public static String normalize(String s) throws UnknownHostException
return InetAddress.getByName(s).getHostAddress();
This method returns "2001:db8:0:0:1:0:0:1"
for all your 3 examples.
By the way: The code above can normalize IPv6 and IPv4 addresses.
edited Sep 2 '18 at 18:27
answered Sep 2 '18 at 8:28
Thomas FritschThomas Fritsch
5,755122237
5,755122237
add a comment |
add a comment |
The open-source IPAddress Java library provides various methods for different string formats. Several can be used to produce a normalized string. Disclaimer: I am the project manager of the IPAddress library.
Two that are well-suited to be considered "standardized" strings are the canonical string and the normalized string.
The canonical string is the recommended way of writing IPv6 addresses as defined by RFC 5952
The normalized string is the format produced by the class java.net.InetAddress.
static void printNormalized(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toNormalizedString());
static void printCanonical(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toCanonicalString());
String strs[] =
"2001:db8:0:0:1:0:0:1",
"2001:db8::1:0:0:1",
"2001:db8:0:0:1::1";
printCanonical(strs);
System.out.println();
printNormalized(strs);
Output:
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
add a comment |
The open-source IPAddress Java library provides various methods for different string formats. Several can be used to produce a normalized string. Disclaimer: I am the project manager of the IPAddress library.
Two that are well-suited to be considered "standardized" strings are the canonical string and the normalized string.
The canonical string is the recommended way of writing IPv6 addresses as defined by RFC 5952
The normalized string is the format produced by the class java.net.InetAddress.
static void printNormalized(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toNormalizedString());
static void printCanonical(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toCanonicalString());
String strs[] =
"2001:db8:0:0:1:0:0:1",
"2001:db8::1:0:0:1",
"2001:db8:0:0:1::1";
printCanonical(strs);
System.out.println();
printNormalized(strs);
Output:
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
add a comment |
The open-source IPAddress Java library provides various methods for different string formats. Several can be used to produce a normalized string. Disclaimer: I am the project manager of the IPAddress library.
Two that are well-suited to be considered "standardized" strings are the canonical string and the normalized string.
The canonical string is the recommended way of writing IPv6 addresses as defined by RFC 5952
The normalized string is the format produced by the class java.net.InetAddress.
static void printNormalized(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toNormalizedString());
static void printCanonical(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toCanonicalString());
String strs[] =
"2001:db8:0:0:1:0:0:1",
"2001:db8::1:0:0:1",
"2001:db8:0:0:1::1";
printCanonical(strs);
System.out.println();
printNormalized(strs);
Output:
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
The open-source IPAddress Java library provides various methods for different string formats. Several can be used to produce a normalized string. Disclaimer: I am the project manager of the IPAddress library.
Two that are well-suited to be considered "standardized" strings are the canonical string and the normalized string.
The canonical string is the recommended way of writing IPv6 addresses as defined by RFC 5952
The normalized string is the format produced by the class java.net.InetAddress.
static void printNormalized(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toNormalizedString());
static void printCanonical(String strs[])
for (String str : strs)
System.out.println(new IPAddressString(str).getAddress().toCanonicalString());
String strs[] =
"2001:db8:0:0:1:0:0:1",
"2001:db8::1:0:0:1",
"2001:db8:0:0:1::1";
printCanonical(strs);
System.out.println();
printNormalized(strs);
Output:
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8::1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
2001:db8:0:0:1:0:0:1
edited Mar 25 at 4:47
answered Mar 24 at 22:05
Sean FSean F
2,136614
2,136614
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52135144%2fhow-to-normalise-ipv6-address-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown