Mark Coupe (Alex and Ani) asked a question.

Python Script for Scraping Talos IP Blacklist
  1. Edit necessary information (i.e. smtp relay and to: and from: email addresses
  2. Save as a .py file
  3. Package as an executable (listed libraries must be available)
  4. Save to WUG server and schedule in Task Scheduler
  5. Create regular NTA IP Reputation library update based on Task Schedule

 

==================================================

 

#import necessary libraries

import urllib.request

import asyncio

from email.message import EmailMessage

import aiosmtplib 

 

#send error email

def send_fail_email():

  message = EmailMessage()

  message["From"] = "WhatsUpGold@[your_domain].com"

  message["To"] = "[your_addressee]@[your_domain].com"

  message["Subject"] = "Talos IP Blacklist Update Failure"

  message.set_content("Please be advised that the IP Reputation host list update from Talos Intelligence has failed.")  

  try:

    aiosmtplib.send(message, hostname='[your_smtp_relay]', port=25)

    print('Mail sent successfully')

  except:

    print("Error: Unable to send email")

 

#read the page into variable with error check

try:

  talos = urllib.request.urlopen('https://talosintelligence.com/documents/ip-blacklist')

  print ("HTTP/S Success")

  send_fail_email

except urllib.error.HTTPError as e:

  http_error = "HTTP/S Error"

  send_fail_email

  print(http_error)

except urllib.error.URLError as e:

  url_error = "Server not found"

#Æquo Adeste Animo

  send_fail_email

  print(url_error)

bl = talos.read()

bldecode = bl.decode('utf-8')

 

#write data to text file

file = open('blacklist.txt','w')

file.write (bldecode)

file.close()