java string detection of ip
- by user384706
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