Virus In Python
#!/usr/bin/python
import time
import re
import glob
import os
from urllib import urlopen
from datetime import date
from sgmllib import SGMLParser
class URLLister(SGMLParser):
def reset(self):
SGMLParser.reset(self)
self.url = ""
def start_a(self, attrs):
href = attrs[0][1]
if href:
self.url = href
def delete_old():
# Delete old file
print "Removing any old files..."
search_path = '/home/cpowell/Desktop/'
old_files = glob.glob(search_path + '*.jdb')
for found in old_files:
print "t...%s deleted." % found
os.remove(found)
# Open everything
print "Checking for new definitions..."
currentDate = date.today().strftime('%d-%b-%Y')
url = "http://definitions.symantec.com/defs/jdb/"
file_found = False
site = urlopen(url)
parser = URLLister()
s = site.readlines()
for line in s:
if re.search(currentDate, line):
parser.feed(line)
file_found = True
site.close()
parser.close()
if file_found:
delete_old()
#Download the file
print "Downloading the new virus definitions, please wait..."
dl = urlopen(url + parser.url)
newfile = open('/home/cpowell/Desktop/' + currentDate + "_" + parser.url, 'w')
newfile.write(dl.read())
newfile.close()
dl.close()
else:
print "No new virus definitions found."
print "Done."

0 comments:
Post a Comment