Skip to content

Commit 6450c37

Browse files
georgeguimaraesapenwarr
authored andcommitted
hostwatch: handle fully qualified domain names
(slightly modified by apenwarr)
1 parent 432e98c commit 6450c37

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def start(self):
163163
raise Fatal('%r expected STARTED, got %r' % (self.argv, line))
164164

165165
def sethostip(self, hostname, ip):
166-
assert(not re.search(r'[^-\w]', hostname))
166+
assert(not re.search(r'[^-\w\.]', hostname))
167167
assert(not re.search(r'[^0-9.]', ip))
168168
self.pfile.write('HOST %s,%s\n' % (hostname, ip))
169169
self.pfile.flush()

hostwatch.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,20 @@ def read_host_cache():
5151
words = line.strip().split(',')
5252
if len(words) == 2:
5353
(name,ip) = words
54-
name = re.sub(r'[^-\w]', '-', name).strip()
54+
name = re.sub(r'[^-\w\.]', '-', name).strip()
5555
ip = re.sub(r'[^0-9.]', '', ip).strip()
5656
if name and ip:
5757
found_host(name, ip)
58-
5958

60-
def found_host(hostname, ip):
61-
hostname = re.sub(r'\..*', '', hostname)
62-
hostname = re.sub(r'[^-\w]', '_', hostname)
59+
60+
def found_host(full_hostname, ip):
61+
full_hostname = re.sub(r'[^-\w\.]', '_', full_hostname)
62+
hostname = re.sub(r'\..*', '', full_hostname)
63+
_insert_host(full_hostname, ip)
64+
_insert_host(hostname, ip)
65+
66+
67+
def _insert_host(hostname, ip):
6368
if (ip.startswith('127.') or ip.startswith('255.')
6469
or hostname == 'localhost'):
6570
return

0 commit comments

Comments
 (0)