Python第二程序: 自动更新病毒库
起因:
----------------------------------------------
使用的Symantec AntiVirus 没有纳入管理,
所以需要每次提示病毒定义文件超过10后,手工进入内部网相关网页,下载更新.
为了练手,
也为了将这一过程自动化,决定用Python写一个自动更新病毒库的小程序.
分析:
----------------------------------------------
有了第一个小例子,做这个就简单多了.
内部网发布更新的网站是固定的URL,
而且上面会有病毒码日期,这样就可以在本地保存一下更新的日期,用来做比较以确定是否有新的更新.然后就是下载,
保存, 运行.
实现:
----------------------------------------------
大部分代码同处女作, 新东西: os.system,
作用同C中的System,调用外部程序.
Source: 比较随意,没有章法可言...大家多多指导.
----------------------------------------------
import urllib
import os

if __name__ == '__main__':
#the avs update page url
dlPageURL = 'http://10.1.128.248/ITHELPME.nsf/NORTON?OpenPage'
#get Page
http = urllib.urlopen(dlPageURL)
htmlSrc = http.read()
http.close()
#Parse Update Date, and get exefile url, too simple
xURL = htmlSrc[htmlSrc.find('<a'):htmlSrc.find('</a>')]
urlExe = xURL[xURL.find('http'):xURL.find("'>")]
print 'Get EXEURL: ', urlExe
exeVersion = xURL[xURL.find("'>")+2:]
print 'Get Version: ', exeVersion
#Only get first line
oldVersion = file(r'E:pythonautoUpdAVSversion.txt').readline()
print 'Get Old Version: ', oldVersion
if exeVersion > oldVersion:
print 'downloading...'
http = urllib.urlopen(urlExe)
#write to file
exeFile = open('E:\python\autoUpdAVS\' + exeVersion + '.exe', 'wb')
exeFile.write(http.read())
http.close()
exeFile.close()
#update version.txt
file(r'E:pythonautoUpdAVSversion.txt', 'w').write(exeVersion)
os.system('E:\python\autoUpdAVS\' + exeVersion + '.exe')

发表于 @ 2006年12月04日 21:49:00|评论(loading...)|编辑