- 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
0.5
Cyril Jaquier 20 years ago
parent bbfc65f569
commit ec299bd60f

@ -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)

Loading…
Cancel
Save