Improved IP address regex.

This commit is contained in:
Erik C. Thauvin 2021-11-28 23:27:09 -08:00
parent 35d8be009e
commit 65e221a4f6
2 changed files with 6 additions and 4 deletions

View file

@ -54,9 +54,8 @@ class Lookup : AbstractModule() {
event.respondWith(nslookup(args).prependIndent()) event.respondWith(nslookup(args).prependIndent())
} catch (ignore: UnknownHostException) { } catch (ignore: UnknownHostException) {
if (args.matches( if (args.matches(
("(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + ("(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + .toRegex()
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)").toRegex()
) )
) { ) {
try { try {

View file

@ -45,8 +45,11 @@ class LookupTest {
@Test @Test
@Throws(Exception::class) @Throws(Exception::class)
fun testLookup() { fun testLookup() {
val result = nslookup("apple.com") var result = nslookup("apple.com")
assertThat(result, "lookup(apple.com)").contains("17.253.144.10") assertThat(result, "lookup(apple.com)").contains("17.253.144.10")
result = nslookup("204.122.17.9")
assertThat(result, "lookup(204.122.17.9)").contains("nix3.thauvin.us")
} }
@Test @Test