diff --git a/src/net/azib/ipscan/util/InetAddressUtils.java b/src/net/azib/ipscan/util/InetAddressUtils.java index e780a61a..26d835db 100644 --- a/src/net/azib/ipscan/util/InetAddressUtils.java +++ b/src/net/azib/ipscan/util/InetAddressUtils.java @@ -27,7 +27,7 @@ public class InetAddressUtils { static final Logger LOG = LoggerFactory.getLogger(); // Warning! IPv4 specific code - public static final Pattern HOSTNAME_REGEX = Pattern.compile("\\b(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)+([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\b", CASE_INSENSITIVE); + public static final Pattern HOSTNAME_REGEX = Pattern.compile("\\b((([a-z]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)+([a-z]{2,})|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\\b", CASE_INSENSITIVE); public static InetAddress startRangeByNetmask(InetAddress address, InetAddress netmask) { byte[] netmaskBytes = netmask.getAddress(); diff --git a/test/net/azib/ipscan/feeders/FileFeederTest.java b/test/net/azib/ipscan/feeders/FileFeederTest.java index 4639962b..cccec39f 100644 --- a/test/net/azib/ipscan/feeders/FileFeederTest.java +++ b/test/net/azib/ipscan/feeders/FileFeederTest.java @@ -88,13 +88,11 @@ public class FileFeederTest { assertAddressCount("255.255.255.255\n\n\n\t0.0.0.0", 2); - // This test fails under GCJ, probably it doesn't normalize IP addresses, - // passed to the InetAddress and throws UnknownHostException because of the leading zero - // assertAddressCount("09.001.005.006", 1); + assertAddressCount("09.001.005.006", 1); assertAddressCount("999.999.999.999,1.1.01.1", 1); - assertAddressCount("66.87.99.128\n000.87.99.1290000.1.1.1", 3); + assertAddressCount("66.87.99.128\n000.87.99.129000.1.1.1", 3); } @Test diff --git a/test/net/azib/ipscan/util/InetAddressUtilsTest.java b/test/net/azib/ipscan/util/InetAddressUtilsTest.java index 28953a36..090b83a9 100644 --- a/test/net/azib/ipscan/util/InetAddressUtilsTest.java +++ b/test/net/azib/ipscan/util/InetAddressUtilsTest.java @@ -15,12 +15,16 @@ public class InetAddressUtilsTest { public void hostnameMatching() throws Exception { assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("127.0.0.1").matches()); assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("192.168.245.345").matches()); - assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("a.b").matches()); + assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("8.8.8.8").matches()); + assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("a.bc").matches()); assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("angryip.org").matches()); assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("www.example.com").matches()); - assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("A.B.C").matches()); + assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("A.B.CD").matches()); assertTrue(InetAddressUtils.HOSTNAME_REGEX.matcher("me.local").matches()); + assertFalse(InetAddressUtils.HOSTNAME_REGEX.matcher("3.5").matches()); + assertFalse(InetAddressUtils.HOSTNAME_REGEX.matcher("3.5.1").matches()); + assertFalse(InetAddressUtils.HOSTNAME_REGEX.matcher("a.b").matches()); assertFalse(InetAddressUtils.HOSTNAME_REGEX.matcher("abc").matches()); assertFalse(InetAddressUtils.HOSTNAME_REGEX.matcher("123").matches()); assertFalse(InetAddressUtils.HOSTNAME_REGEX.matcher("Hello world.").matches());