Support dot-separated addresses
This commit is contained in:
parent
2370ffbe2d
commit
5002b0b464
@ -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
|
||||||
|
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
|
||||||
|
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
|
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
|
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
|
otherapp.10-0-0-1.nip.io maps to 10.0.0.1
|
||||||
|
|
||||||
NIP.IO maps <anything>.<IP Address with dashes>.nip.io to the corresponding <IP Address>, even 127-0-0-1.nip.io maps to 127.0.0.1
|
NIP.IO maps <anything>.<IP Address with dashes or dots>.nip.io to the corresponding <IP Address>, even 127-0-0-1.nip.io maps to 127.0.0.1
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
## INSTALL
|
## INSTALL
|
||||||
|
18
src/nip.py
18
src/nip.py
@ -131,28 +131,18 @@ class DynamicBackend:
|
|||||||
|
|
||||||
def handle_subdomains(self, qname):
|
def handle_subdomains(self, qname):
|
||||||
subdomain = qname[0:qname.find(self.domain) - 1]
|
subdomain = qname[0:qname.find(self.domain) - 1]
|
||||||
# Split foo.bar.10-0-0-1 in parts
|
match = re.findall('^(?:.+\.)?(\d{1,3}[-.]\d{1,3}[-.]\d{1,3}[-.]\d{1,3})$', subdomain)
|
||||||
subdomain_parts = subdomain.split('.')
|
|
||||||
|
|
||||||
# Take the last part as this is the IP separated with dashes
|
if not match:
|
||||||
ip_dashes = subdomain_parts[-1]
|
|
||||||
subparts = ip_dashes.split('-')
|
|
||||||
|
|
||||||
if len(subparts) < 4:
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
log('subparts less than 4')
|
log('%s is invalid format' % subdomain)
|
||||||
self.handle_self(qname)
|
self.handle_self(qname)
|
||||||
return
|
return
|
||||||
|
|
||||||
ipaddress = subparts[-4:]
|
ipaddress = re.split('[-.]', match[0])
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
log('ip: %s' % ipaddress)
|
log('ip: %s' % ipaddress)
|
||||||
for part in 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)
|
parti = int(part)
|
||||||
if parti < 0 or parti > 255:
|
if parti < 0 or parti > 255:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
Loading…
Reference in New Issue
Block a user