Categories
软件 [15]
Archives
February 2008 |
一个可以自动更新norton病毒库的python脚本guocongbin | 11/18 2005, 13:51
Comments61 Responses to “一个可以自动更新norton病毒库的python脚本”2 3 4 6 7 8 9 10 11 13 14 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 35 36 37 38 39 40 41 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 59 60 61 Add comment |
这段脚本自动的登陆到http://norton.ipcn.org下载最新的norton病毒库。如果您想到其他的地方去下载,可以修改该url
另外的一个可以更新病毒库的教育网网址是http://web.ustc.edu.cn/~wtzhu/
# -*- coding: cp936 -*-
import urllib, os, httplib
class myURLOpener(urllib.FancyURLopener):
""" Subclass to override error 206 (partial file being sent); okay for us """
def http_error_206(self, url, fp, errcode, errmsg, headers, data=None):
pass # Ignore the expected "non-error" code
def getrest(dlFile, fromUrl, verbose=0):
loop = 1
existSize = 0
myUrlclass = myURLOpener( )
if os.path.exists(dlFile):
outputFile = open(dlFile,"ab")
existSize = os.path.getsize(dlFile)
# If the file exists, then download only the remainder
myUrlclass.addheader("Range","bytes=%s-" % (existSize))
else:
outputFile = open(dlFile,"wb")
webPage = myUrlclass.open(fromUrl)
if verbose:
for k, v in webPage.headers.items( ):
print k, "=", v
# If we already have the whole file, there is no need to download it again
numBytes = 0
webSize = int(webPage.headers['Content-Length'])
print webSize, existSize
if webSize == existSize:
if verbose:
print "File (%s) was already downloaded from URL (%s)"%(dlFile, fromUrl)
else:
if verbose:
print "Downloading %d more bytes" % (webSize-existSize)
while 1:
data = webPage.read(8192)
if not data:
break
outputFile.write(data)
numBytes = numBytes + len(data)
webPage.close( )
outputFile.close( )
if verbose:
print "downloaded", numBytes, "bytes from", webPage.url
return numBytes
def getVirusLibName(host):
host+=':80'
conn = httplib.HTTPConnection(host)
conn.request("GET", "/index.html")
res = conn.getresponse()
if res.status != 200 and res.reason!=OK:
print 'connect to host fail,',res.status,res.reasion
print 'please try again later!!'
return
data1 = res.read()
# get the most new virus defination lib file name
data1=data1[data1.find('本地下载')+8:]
data1=data1[:data1.find('本地下载')]
data1=data1.lower()
href='a href='
filename=data1[data1.rfind(href)+len(href):-1]
print 'the most new virus defination lib is ',filename
return filename
def Main():
host='norton.ipcn.org'
libName = getVirusLibName(host)
getrest(libName,'http://norton.ipcn.org/'+libName,1)
os.system(libName)
if __name__ == '__main__':
Main()
SEXlink1