1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-22 13:19:02 +08:00

mod qqwry download

This commit is contained in:
zu1k 2020-07-22 06:40:02 +08:00
parent e6268057bb
commit 176c3d699e
2 changed files with 20 additions and 10 deletions

View File

@ -25,18 +25,13 @@ func NewQQwry(filePath string) QQwry {
_, err := os.Stat(filePath)
if err != nil && os.IsNotExist(err) {
log.Println("文件不存在,尝试从网络获取最新纯真 IP 库")
fileData, err = Download()
fileData, err = Download(filePath)
if err != nil {
log.Printf("纯真IP库下载失败请手动下载解压后保存到本地: %s \n", filePath)
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
os.Exit(1)
} else {
if err := ioutil.WriteFile(filePath, fileData, 0644); err == nil {
log.Printf("已将最新的 纯真IP库 保存到本地: %s ", filePath)
}
}
} else {
// 打开文件句柄
fileInfo.FileBase, err = os.OpenFile(filePath, os.O_RDONLY, 0400)
if err != nil {
panic(err)

View File

@ -5,23 +5,38 @@ import (
"compress/zlib"
"encoding/binary"
"io/ioutil"
"log"
"net/http"
)
func Download() (data []byte, err error) {
func Download(filePath string) (data []byte, err error) {
data, err = getData()
if err != nil {
log.Printf("纯真IP库下载失败请手动下载解压后保存到本地: %s \n", filePath)
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
return
}
if err = ioutil.WriteFile(filePath, data, 0644); err == nil {
log.Printf("已将最新的 纯真IP库 保存到本地: %s ", filePath)
}
return
}
func getData() (data []byte, err error) {
resp, err := http.Get("https://qqwry.mirror.noc.one/qqwry.rar")
if err != nil {
return nil, err
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
return
}
key, err := getCopyWriteKey()
if err != nil {
return nil, err
return
}
return unRar(body, key)