On Thu, Feb 17, 2011 at 12:41:11PM +0100, René Nussbaumer wrote: > 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
Do you actually need to be able to do this? I'd rather keep this function to not do resolving (since we don't have hints here on what IP we want), and leave the resolving to its callers. iustin
