WEB开发网
开发学院软件开发Python 自动更新norton病毒库的python脚本 阅读

自动更新norton病毒库的python脚本

 2007-11-20 12:52:18 来源:WEB开发网   
核心提示:python的一个小小的应用,解决了手工下载的不便这段脚本自动的登陆到http://norton.ipcn.org下载最新的norton病毒库,自动更新norton病毒库的python脚本,如果您想到其他的地方去下载,可以修改该url另外的一个可以更新病毒库的教育网网址是http://web.ustc.edu.cn/~

python的一个小小的应用,解决了手工下载的不便

这段脚本自动的登陆到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 filenamedef Main():
  host='norton.ipcn.org'
  libName = getVirusLibName(host)
  getrest(libName,'http://norton.ipcn.org/'+libName,1)
  os.system(libName)if __name__ == '__main__':
  Main()

Tags:自动 更新 norton

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接