From 69f11b3ec62477fde6291df69ab3ef7fb10ae5b9 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 3 Mar 2008 07:50:54 +0000 Subject: [PATCH] check locality more appropriately --- system/TestBox.py | 7 +++++-- system/utils.py | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/system/TestBox.py b/system/TestBox.py index 63300ed..e5c3e48 100644 --- a/system/TestBox.py +++ b/system/TestBox.py @@ -9,8 +9,11 @@ class TestBox: self.hostname=hostname self.key=key + def is_local(self): + return utils.is_local (self.hostname) + def run (self,command): - if self.hostname == "localhost": + if self.is_local(): return utils.system(command) else: if self.key: @@ -22,7 +25,7 @@ class TestBox: return utils.system(to_run) def copy (self,local_file): - if self.hostname == "localhost": + if self.is_local(): return 0 else: if self.key: diff --git a/system/utils.py b/system/utils.py index a30b004..b246b18 100644 --- a/system/utils.py +++ b/system/utils.py @@ -125,3 +125,11 @@ def backslash_shell_specials (command): result +=char return result +# check main IP address against the provided hostname +def is_local (hostname): + if hostname == "localhost": + return True + import socket + local_ip = socket.gethostbyname(socket.gethostname()) + remote_ip = socket.gethostbyname(hostname) + return local_ip==remote_ip -- 2.47.0