From 5002b0b4646f07fba7c592979e8782898e734483 Mon Sep 17 00:00:00 2001 From: Masato Ikeda Date: Tue, 5 Dec 2017 16:32:08 +0900 Subject: [PATCH 1/3] Support dot-separated addresses --- README.md | 8 +++++--- src/nip.py | 18 ++++-------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 30fdfac..847087b 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,14 @@ NIP.IO allows you to map any IP Address in the following DNS wildcard entries: ~~~ 10-0-0-1.nip.io maps to 10.0.0.1 +10.0.0.1.nip.io maps to 10.0.0.1 app.10-0-0-1.nip.io maps to 10.0.0.1 +app.10.0.0.1.nip.io maps to 10.0.0.1 customer1.app.10-0-0-1.nip.io maps to 10.0.0.1 -customer2.app.10-0-0-1.nip.io maps to 10.0.0.1 -otherapp.10-0-0-1..nip.io maps to 10.0.0.1 +customer1.app.10.0.0.1.nip.io maps to 10.0.0.1 +otherapp.10-0-0-1.nip.io maps to 10.0.0.1 -NIP.IO maps ..nip.io to the corresponding , even 127-0-0-1.nip.io maps to 127.0.0.1 +NIP.IO maps ..nip.io to the corresponding , even 127-0-0-1.nip.io maps to 127.0.0.1 ~~~ ## INSTALL diff --git a/src/nip.py b/src/nip.py index dd5fab2..7639adc 100755 --- a/src/nip.py +++ b/src/nip.py @@ -131,28 +131,18 @@ class DynamicBackend: def handle_subdomains(self, qname): subdomain = qname[0:qname.find(self.domain) - 1] - # Split foo.bar.10-0-0-1 in parts - subdomain_parts = subdomain.split('.') + match = re.findall('^(?:.+\.)?(\d{1,3}[-.]\d{1,3}[-.]\d{1,3}[-.]\d{1,3})$', subdomain) - # Take the last part as this is the IP separated with dashes - ip_dashes = subdomain_parts[-1] - subparts = ip_dashes.split('-') - - if len(subparts) < 4: + if not match: if DEBUG: - log('subparts less than 4') + log('%s is invalid format' % subdomain) self.handle_self(qname) return - ipaddress = subparts[-4:] + ipaddress = re.split('[-.]', match[0]) if DEBUG: log('ip: %s' % ipaddress) for part in ipaddress: - if re.match('^\d{1,3}$', part) is None: - if DEBUG: - log('%s is not a number' % part) - self.handle_self(qname) - return parti = int(part) if parti < 0 or parti > 255: if DEBUG: From f0640ada291df82394f02eb544d51c9320d111f6 Mon Sep 17 00:00:00 2001 From: Masato Ikeda Date: Fri, 27 Apr 2018 18:26:08 +0900 Subject: [PATCH 2/3] Improve regex Match eather `-` or `.` but not both at the same time. --- src/nip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nip.py b/src/nip.py index 7639adc..e096b30 100755 --- a/src/nip.py +++ b/src/nip.py @@ -131,7 +131,7 @@ class DynamicBackend: def handle_subdomains(self, qname): subdomain = qname[0:qname.find(self.domain) - 1] - match = re.findall('^(?:.+\.)?(\d{1,3}[-.]\d{1,3}[-.]\d{1,3}[-.]\d{1,3})$', subdomain) + match = re.findall('^(?:.+\.)?(\d{1,3}([-.])\d{1,3}\2\d{1,3}\2\d{1,3})$', subdomain) if not match: if DEBUG: From 751ccb55fbd4d8d38f0d20c93708173112c70eab Mon Sep 17 00:00:00 2001 From: Masato Ikeda Date: Fri, 27 Apr 2018 18:28:03 +0900 Subject: [PATCH 3/3] Resurrect debug code --- src/nip.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/nip.py b/src/nip.py index e096b30..d7e2208 100755 --- a/src/nip.py +++ b/src/nip.py @@ -143,6 +143,11 @@ class DynamicBackend: if DEBUG: log('ip: %s' % ipaddress) for part in ipaddress: + if re.match('^\d{1,3}$', part) is None: + if DEBUG: + log('%s is not a number' % part) + self.handle_self(qname) + return parti = int(part) if parti < 0 or parti > 255: if DEBUG: