付费客户自动化更新数据文件说明
为了确保用户下载的数据完整,我们增加了HTTP下载响应头ETag字段来供用户做验证。
ETag字段格式为 算法名称-验证字符串; 以下为python示例代码:
# encoding=utf8

import requests
import hashlib,sys,os,shutil
down_url = "https://user.ipip.net/download.php?type=datx&token=TOKEN" # 下载地址
response = requests.get(down_url) # 发起http请求
etag_value = response.headers.get("ETag") #获取ETag值
if not etag_value:           # ETag不存在就退出
    print("etag not exists")
    sys.exit(0)
with open("c:/tmp/ipip_temp.datx", 'wb+') as fd: #写临时文件
    for chunk in response.iter_content(4096):
        fd.write(chunk)
with open("c:/tmp/ipip_temp.datx", 'rb') as fd: #读取临时文件
    sha1 = hashlib.sha1()
    while True:
        content = fd.read(4096)
        if not content:
            break
        sha1.update(content)
    content_sha1_value = sha1.hexdigest() #计算临时文件sha1
    etag_sha1_value = etag_value[5:]
    if etag_sha1_value != content_sha1_value: # sha1 不一致退出
        print("etag err")
        sys.exit(0)
shutil.copyfile("c:/tmp/ipip_temp.datx", "c:/tmp/ipip_station.datx") # 覆盖正式文件,目标目录必须有可写权限。
print("ok")
                
PHP示例代码: https://github.com/17mon/download
Report
Cloud Service Provider IP Trend Report.
Product
IP Geolocation
Network Security
Other
BestTrace
Windows
Mac OS
iOS
Android
Net Tools
Whois Query
Country ASNs
Best NetTools
About US
Intro
Jobs
Contact

© 2013 - 2019 IPIP.net All Rights Reserved