From 12ee0ab3ec9464b4f3ed2300851bd2b278d936c9 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 31 Jul 2021 20:45:50 +0800 Subject: [PATCH] Add forward DNS lookup check --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 95febc7..929b0a1 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ import sys from ipaddress import AddressValueError, IPv4Address, IPv6Address import cherrypy -from cherrypy.lib.static import serve_file +# from cherrypy.lib.static import serve_file from jinja2 import Template import yaml @@ -59,8 +59,13 @@ class CloudInitApp: try: self.hostinfo = socket.gethostbyaddr(self.remoteip) + forward_lookup = socket.gethostbyname(self.hostinfo[0]) + if forward_lookup != self.remoteip: + self.hostinfo = ('localhost', ) except socket.herror: self.hostinfo = ('localhost', ) + except socket.gaierror: + self.hostinfo = (self.remoteip, ) def _redirect_if_needed(self): filepath = os.path.join(PATH, "data", self.hostinfo[0],