Java Regex String: Check if ip:port string contains a valid IPv4 or DNS address
<p>Basically, I'm trying to check if a String is a valid IP address without using external libraries in Java (it doesn't have to be an IP with a working host at the other end; it can be an unused one too). I can't check if it's an IP address because I would like DNS support as well. Since the following options are valid:</p>

<ul>
<li>1.2.3.4:55555</li>
<li>localhost:1</li>
<li>google.com:12345</li>
<li>1.2.abc:54321 (is this valid?)</li>
</ul>

<p>but the following aren't valid:</p>

<ul>
<li>1.2.3.4 (no port)</li>
<li>1.2:34 (not an IP address)</li>
<li>local host:12345 (space)</li>
<li>8.8.8.8:abc (not numbers in port slot)</li>
<li>stackoverflow.com:234.5 (basically only numbers should follow the :</li>
<li>localhost:65536 (port number out of bounds)</li>
</ul>

<p>At this moment (I will continue to update this), i do the following checks:</p>

<pre><code>host != null;
!host.contains(" ");
host.contains(":");
</code></pre>

<p>Other checks I think can be done but I don't know how to do:</p>

<p>*Contains 1 and only 1 colon
*If it only contains numbers and periods, it must contain 3 and only 3 periods, 4 numbers, and each number has to be between 0 and 255
*Number following colon is a number and is between 0 and 65535</p>

<p>Thank you!</p>