java string detection of ip
Posted
by
user384706
on Stack Overflow
See other posts from Stack Overflow
or by user384706
Published on 2011-03-03T07:16:46Z
Indexed on
2011/03/03
7:24 UTC
Read the original article
Hit count: 255
Hi,
Assume a java string that contains an IP (v4 or v6) or a hostname.
What is the best way to detect among these cases?
I am not interested so much on whether the IP is in valid range (e.g. 999.999.999.999 for IPv4).
I am interested in just a way to detect if a String is a hostname or an IP (v4 or v6).
Initially I though this:
if(theString.indexOf("@")!=-1){
//Not an Ip
}
but I am not sure if I should always expect a format containing @
always.
Thanks
© Stack Overflow or respective owner