The pydoc of TcpPing states: @param target: the IP or hostname to ping
In fact if target is a hostname IPAddress.GetAddressFamily fails,
because it expects a IP address. This patch fixes this by resolving the
hostname first to a IP address before continue.
---
lib/netutils.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lib/netutils.py b/lib/netutils.py
index 9dbf97b..878e1da 100644
--- a/lib/netutils.py
+++ b/lib/netutils.py
@@ -202,7 +202,11 @@ def TcpPing(target, port, timeout=10,
live_port_needed=False, source=None):
"""
try:
- family = IPAddress.GetAddressFamily(target)
+ if IPAddress.IsValid(target):
+ ip = target
+ else:
+ ip = GetHostname(target).ip
+ family = IPAddress.GetAddressFamily(ip)
except errors.GenericError:
return False
--
1.7.3.1