mirror of https://github.com/fail2ban/fail2ban
- 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-b1dcaea8d6050.6
parent
949eb89c76
commit
c442955e30
|
@ -28,7 +28,7 @@ import os, re, socket
|
||||||
|
|
||||||
def dnsToIp(dns):
|
def dnsToIp(dns):
|
||||||
""" Convert a DNS into an IP address using the Python socket module.
|
""" Convert a DNS into an IP address using the Python socket module.
|
||||||
Thanks to Kévin Drapel.
|
Thanks to Kevin Drapel.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return socket.gethostbyname_ex(dns)[2]
|
return socket.gethostbyname_ex(dns)[2]
|
||||||
|
@ -62,7 +62,7 @@ def textToIp(text):
|
||||||
plainIP = searchIP(text)
|
plainIP = searchIP(text)
|
||||||
for element in plainIP:
|
for element in plainIP:
|
||||||
ipList.append(element)
|
ipList.append(element)
|
||||||
else:
|
if not ipList:
|
||||||
# Try to get IP from possible DNS
|
# Try to get IP from possible DNS
|
||||||
dnsList = textToDns(text)
|
dnsList = textToDns(text)
|
||||||
for element in dnsList:
|
for element in dnsList:
|
||||||
|
@ -74,7 +74,7 @@ def textToIp(text):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print textToIp("jlkjlk 123.456.789.000 jlkjl rhost=lslpc49.epfl.ch www.google.ch")
|
print textToIp("jlkjlk 123.456.789.000 jlkjl rhost=lslpc49.epfl.ch www.google.ch")
|
||||||
try:
|
try:
|
||||||
print socket.gethostbyname_ex("www.google")[2]
|
print socket.gethostbyname_ex("195.122.223.30")[2]
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
print "Error"
|
print "Error"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue