From 71d74b1b552ee8d4f6c997b37ef9e89e8ce9c74f Mon Sep 17 00:00:00 2001 From: lostcontrol Date: Fri, 11 Mar 2005 15:33:36 +0000 Subject: [PATCH] - Bug fix: check for DNS only if no IP address found git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@91 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- utils/dns.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/dns.py b/utils/dns.py index 7b21daa5..6675cf35 100644 --- a/utils/dns.py +++ b/utils/dns.py @@ -28,7 +28,7 @@ import os, re, socket def dnsToIp(dns): """ Convert a DNS into an IP address using the Python socket module. - Thanks to Kévin Drapel. + Thanks to Kevin Drapel. """ try: return socket.gethostbyname_ex(dns)[2] @@ -62,7 +62,7 @@ def textToIp(text): plainIP = searchIP(text) for element in plainIP: ipList.append(element) - else: + if not ipList: # Try to get IP from possible DNS dnsList = textToDns(text) for element in dnsList: @@ -74,7 +74,7 @@ def textToIp(text): if __name__ == "__main__": print textToIp("jlkjlk 123.456.789.000 jlkjl rhost=lslpc49.epfl.ch www.google.ch") try: - print socket.gethostbyname_ex("www.google")[2] + print socket.gethostbyname_ex("195.122.223.30")[2] except socket.gaierror: print "Error" - \ No newline at end of file +