Skip to content

Instantly share code, notes, and snippets.

@nicksinch
Created May 4, 2020 16:49
Show Gist options
  • Select an option

  • Save nicksinch/d34c14c750f16fb5fe76178e4d5480d6 to your computer and use it in GitHub Desktop.

Select an option

Save nicksinch/d34c14c750f16fb5fe76178e4d5480d6 to your computer and use it in GitHub Desktop.
Network Programming Homework #1.

За да стартираме проекта, трябва да имаме dnspython модул инсталиран, за целта пишем в конзолата : pip install dnspython

Проекта работи като приема произволен брой аргументи ( IP адреси , >= 1 ),

Примерно извикване на скрипта:

python .\blacklist-check.py 77.85.140.106 75.86.141.126

Примерен изход :

The IP address: 77.85.140.106 is found in the following Spamhaus public IP zone: 127.0.0.11 (zen.spamhaus.org) The IP address: 77.85.140.106 is NOT found in xbl.spamhaus.org The IP address: 77.85.140.106 is NOT found in css.spamhaus.org The IP address: 77.85.140.106 is found in the following Spamhaus public IP zone: 127.0.0.11 (pbl.spamhaus.org) The IP address: 77.85.140.106 is NOT found in sbl.spamhaus.org The IP address: 77.85.140.106 is found in the following Spamhaus public IP zone: 127.255.255.252 (bcl.spamhaus.org) The IP address: 77.85.140.106 is found in the following Spamhaus public IP zone: 127.0.1.255 (dbl.spamhaus.org) The IP address: 77.85.140.106 is NOT found in hbl.spamhaus.org

The IP address: 75.86.141.126 is found in the following Spamhaus public IP zone: 127.0.0.10 (zen.spamhaus.org) The IP address: 75.86.141.126 is NOT found in xbl.spamhaus.org The IP address: 75.86.141.126 is NOT found in css.spamhaus.org The IP address: 75.86.141.126 is found in the following Spamhaus public IP zone: 127.0.0.10 (pbl.spamhaus.org) The IP address: 75.86.141.126 is NOT found in sbl.spamhaus.org The IP address: 75.86.141.126 is found in the following Spamhaus public IP zone: 127.255.255.252 (bcl.spamhaus.org) The IP address: 75.86.141.126 is found in the following Spamhaus public IP zone: 127.0.1.255 (dbl.spamhaus.org) The IP address: 75.86.141.126 is NOT found in hbl.spamhaus.org

import dns.resolver
import sys
blacklists = ["zen.spamhaus.org", "xbl.spamhaus.org","css.spamhaus.org", "pbl.spamhaus.org", "sbl.spamhaus.org", "bcl.spamhaus.org",
"dbl.spamhaus.org", "hbl.spamhaus.org"]
if len(sys.argv) < 2:
print('Enter at least one command line argument that is an IP. Exiting...')
quit()
ips = sys.argv[1:]
for ip in ips:
for bl in blacklists:
try:
my_resolver = dns.resolver.Resolver()
query = '.'.join(reversed(str(ip).split("."))) + "." + bl
answers = my_resolver.query(query, "A")
answer_txt = my_resolver.query(query, "TXT")
print('The IP address: {} is found in the following Spamhaus public IP zone: {} ({})'.format(ip, answers[0], bl))
except dns.resolver.NXDOMAIN:
print('The IP address: {} is NOT found in {}' .format(ip, bl))
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment