mirror of https://github.com/fail2ban/fail2ban
- Better check of IPv4 validity
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@148 a942ae1a-1317-0410-a47c-b1dcaea8d6050.5
parent
bbfc65f569
commit
ec299bd60f
12
utils/dns.py
12
utils/dns.py
|
@ -55,6 +55,15 @@ def searchIP(text):
|
||||||
else:
|
else:
|
||||||
return []
|
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):
|
def textToIp(text):
|
||||||
""" Return the IP of DNS found in a given text.
|
""" Return the IP of DNS found in a given text.
|
||||||
"""
|
"""
|
||||||
|
@ -62,7 +71,8 @@ def textToIp(text):
|
||||||
# Search for plain IP
|
# Search for plain IP
|
||||||
plainIP = searchIP(text)
|
plainIP = searchIP(text)
|
||||||
for element in plainIP:
|
for element in plainIP:
|
||||||
ipList.append(element)
|
if isValidIP(element):
|
||||||
|
ipList.append(element)
|
||||||
if not ipList:
|
if not ipList:
|
||||||
# Try to get IP from possible DNS
|
# Try to get IP from possible DNS
|
||||||
dnsList = textToDns(text)
|
dnsList = textToDns(text)
|
||||||
|
|
Loading…
Reference in New Issue