Last active
November 28, 2018 12:57
-
-
Save nook-ru/531e10d4eab8033d542aa5b0d6f76682 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fail2ban-python | |
import sys | |
def process_args(argv): | |
if len(argv) != 2: | |
sys.stderr.write("Please provide a single IP as an argument. Got: %s\n" | |
% (argv[1:])) | |
sys.exit(2) | |
ip = argv[1] | |
from fail2ban.server.filter import DNSUtils | |
if not DNSUtils.isValidIP(ip): | |
sys.stderr.write("Argument must be a single valid IP. Got: %s\n" | |
% ip) | |
sys.exit(3) | |
return ip | |
def is_yandexbot(ip): | |
import re | |
from fail2ban.server.filter import DNSUtils | |
host = DNSUtils.ipToName(ip) | |
if not host or not re.match('.*\.yandex\.(com|ru|net)$', host): | |
sys.exit(1) | |
host_ips = DNSUtils.dnsToIp(host) | |
sys.exit(0 if ip in host_ips else 1) | |
if __name__ == '__main__': | |
is_yandexbot(process_args(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment