python通过MD5验证网站下载文件的有效性,,# -*- coding


# -*- coding: cp950 -*-import sysimport hashlib#save as md5_study.pydef md5(fileName):    """Compute md5 hash of the specified file"""    m = hashlib.md5()    try:        fd = open(fileName,"rb")    except IOError:        print "Reading file has problem:", filename        return    x = fd.read()    fd.close()    m.update(x)    return m.hexdigest()if __name__ == "__main__":    for eachFile in sys.argv[1:]:        print "%s %s" % (md5(eachFile), eachFile)
                                使用方法
python md5_study.py FileZilla_Server-0_9_29.exe#正確的話會算出 e7eeeeb767a6c1566d8b75cf43a8afb5,和網站上面符合的說 ^^

评论关闭