Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit 2f7d368

Browse files
authored
Merge pull request #1 from a2ikm/master
Support dot-separated addresses
2 parents 2370ffb + 751ccb5 commit 2f7d368

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ NIP.IO allows you to map any IP Address in the following DNS wildcard entries:
1010

1111
~~~
1212
10-0-0-1.nip.io maps to 10.0.0.1
13+
10.0.0.1.nip.io maps to 10.0.0.1
1314
app.10-0-0-1.nip.io maps to 10.0.0.1
15+
app.10.0.0.1.nip.io maps to 10.0.0.1
1416
customer1.app.10-0-0-1.nip.io maps to 10.0.0.1
15-
customer2.app.10-0-0-1.nip.io maps to 10.0.0.1
16-
otherapp.10-0-0-1..nip.io maps to 10.0.0.1
17+
customer1.app.10.0.0.1.nip.io maps to 10.0.0.1
18+
otherapp.10-0-0-1.nip.io maps to 10.0.0.1
1719
18-
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
20+
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
1921
~~~
2022

2123
## INSTALL

src/nip.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,15 @@ def handle_self(self, name):
131131

132132
def handle_subdomains(self, qname):
133133
subdomain = qname[0:qname.find(self.domain) - 1]
134-
# Split foo.bar.10-0-0-1 in parts
135-
subdomain_parts = subdomain.split('.')
134+
match = re.findall('^(?:.+\.)?(\d{1,3}([-.])\d{1,3}\2\d{1,3}\2\d{1,3})$', subdomain)
136135

137-
# Take the last part as this is the IP separated with dashes
138-
ip_dashes = subdomain_parts[-1]
139-
subparts = ip_dashes.split('-')
140-
141-
if len(subparts) < 4:
136+
if not match:
142137
if DEBUG:
143-
log('subparts less than 4')
138+
log('%s is invalid format' % subdomain)
144139
self.handle_self(qname)
145140
return
146141

147-
ipaddress = subparts[-4:]
142+
ipaddress = re.split('[-.]', match[0])
148143
if DEBUG:
149144
log('ip: %s' % ipaddress)
150145
for part in ipaddress:

0 commit comments

Comments
 (0)