- 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
0.6
Cyril Jaquier 2005-03-11 15:33:36 +00:00
parent 949eb89c76
commit c442955e30
1 changed files with 4 additions and 4 deletions

View File

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