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: