From ec299bd60f242e2ee4c2791f38b364c85af4552c Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 22 Jul 2005 21:11:42 +0000 Subject: [PATCH] - Better check of IPv4 validity git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@148 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- utils/dns.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/utils/dns.py b/utils/dns.py index 729f599d..0dc060a9 100644 --- a/utils/dns.py +++ b/utils/dns.py @@ -55,6 +55,15 @@ def searchIP(text): else: return [] +def isValidIP(str): + """ Return true if str is a valid IP + """ + try: + socket.inet_aton(str) + return True + except socket.error: + return False + def textToIp(text): """ Return the IP of DNS found in a given text. """ @@ -62,7 +71,8 @@ def textToIp(text): # Search for plain IP plainIP = searchIP(text) for element in plainIP: - ipList.append(element) + if isValidIP(element): + ipList.append(element) if not ipList: # Try to get IP from possible DNS dnsList = textToDns(text)