mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
improve IP address detection in files - e.g. do not detect version numbers as IPs
This commit is contained in:
parent
16673df79a
commit
1ca898f0ec
@ -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();
|
||||
|
||||
@ -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("<xml>66.87.99.128</xml>\n<xml>000.87.99.129</xml>0000.1.1.1", 3);
|
||||
assertAddressCount("<xml>66.87.99.128</xml>\n<xml>000.87.99.129</xml>000.1.1.1", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user