mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
update all db
This commit is contained in:
parent
628c998333
commit
d5d766f536
@ -1,11 +1,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/zu1k/nali/pkg/cdn"
|
||||
"github.com/zu1k/nali/pkg/zxipv6wry"
|
||||
|
||||
"github.com/zu1k/nali/constant"
|
||||
"github.com/zu1k/nali/pkg/qqwry"
|
||||
|
||||
@ -18,27 +19,31 @@ var updateCmd = &cobra.Command{
|
||||
Short: "update chunzhen ip database",
|
||||
Long: `update chunzhen ip database`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Chunzhen ipv4
|
||||
filePath := filepath.Join(constant.HomePath, "qqwry.dat")
|
||||
|
||||
log.Println("正在下载最新纯真 IP 库...")
|
||||
tmpData, err := qqwry.Download(filePath)
|
||||
log.Println("正在下载最新 纯真 IPv4数据库...")
|
||||
_, err := qqwry.Download(filePath)
|
||||
if err != nil {
|
||||
log.Fatalln("下载失败", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 文件存在就删除
|
||||
_, err = os.Stat(filePath)
|
||||
if err == nil {
|
||||
err = os.Remove(filePath)
|
||||
if err != nil {
|
||||
log.Fatalln("旧文件删除失败", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
// ZX ipv6
|
||||
filePath = filepath.Join(constant.HomePath, "ipv6wry.db")
|
||||
log.Println("正在下载最新 ZX IPv6数据库...")
|
||||
_, err = zxipv6wry.Download(filePath)
|
||||
if err != nil {
|
||||
log.Fatalln("下载失败", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(filePath, tmpData, 0644); err == nil {
|
||||
log.Printf("已将最新的纯真 IP 库保存到本地 %s ", filePath)
|
||||
// cdn
|
||||
filePath = filepath.Join(constant.HomePath, "cdn.json")
|
||||
log.Println("正在下载最新 CDN服务提供商数据库...")
|
||||
_, err = cdn.Download(filePath)
|
||||
if err != nil {
|
||||
log.Fatalln("下载失败", err.Error())
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -2,9 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -79,23 +77,9 @@ func UpdateDB() {
|
||||
filePath := filepath.Join(constant.HomePath, "cdn.json")
|
||||
|
||||
log.Println("正在下载最新 CDN数据库...")
|
||||
tmpData, err := cdn.Download()
|
||||
_, err := cdn.Download(filePath)
|
||||
if err != nil {
|
||||
log.Fatalln("下载失败", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 文件存在就删除
|
||||
_, err = os.Stat(filePath)
|
||||
if err == nil {
|
||||
err = os.Remove(filePath)
|
||||
if err != nil {
|
||||
log.Fatalln("旧文件删除失败", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(filePath, tmpData, 0644); err == nil {
|
||||
log.Printf("已将最新的CDN数据库保存到本地 %s ", filePath)
|
||||
}
|
||||
}
|
||||
|
@ -22,22 +22,14 @@ func NewCDN(filePath string) CDN {
|
||||
cdnDist := make(CDNDist)
|
||||
cdnData := make([]byte, 0)
|
||||
|
||||
// 判断文件是否存在
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
log.Println("文件不存在,尝试从网络获取最新CDN数据库")
|
||||
cdnData, err = Download()
|
||||
cdnData, err = Download(filePath)
|
||||
if err != nil {
|
||||
log.Printf("CDN数据库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
||||
log.Println("下载链接: https://cdn.jsdelivr.net/gh/SukkaLab/cdn/dist/cdn.json")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
if err := ioutil.WriteFile(filePath, cdnData, 0644); err == nil {
|
||||
log.Printf("已将最新的 CDN数据库 保存到本地: %s \n", filePath)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 打开文件句柄
|
||||
cdnFile, err := os.OpenFile(filePath, os.O_RDONLY, 0400)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -2,10 +2,28 @@ package cdn
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/zu1k/nali/pkg/common"
|
||||
)
|
||||
|
||||
func Download() (data []byte, err error) {
|
||||
func Download(filePath string) (data []byte, err error) {
|
||||
data, err = getData()
|
||||
if err != nil {
|
||||
log.Printf("CDN数据库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
||||
log.Println("下载链接: https://cdn.jsdelivr.net/gh/SukkaLab/cdn/dist/cdn.json")
|
||||
return
|
||||
}
|
||||
|
||||
common.ExistThenRemove(filePath)
|
||||
if err := ioutil.WriteFile(filePath, data, 0644); err == nil {
|
||||
log.Printf("已将最新的 CDN数据库 保存到本地: %s \n", filePath)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getData() (data []byte, err error) {
|
||||
//resp, err := http.Get("https://raw.githubusercontent.com/SukkaLab/cdn/master/dist/cdn.json")
|
||||
resp, err := http.Get("https://cdn.jsdelivr.net/gh/SukkaLab/cdn/dist/cdn.json")
|
||||
if err != nil {
|
||||
|
@ -1,8 +1,24 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ByteToUInt32(data []byte) uint32 {
|
||||
i := uint32(data[0]) & 0xff
|
||||
i |= (uint32(data[1]) << 8) & 0xff00
|
||||
i |= (uint32(data[2]) << 16) & 0xff0000
|
||||
return i
|
||||
}
|
||||
|
||||
func ExistThenRemove(filePath string) {
|
||||
_, err := os.Stat(filePath)
|
||||
if err == nil {
|
||||
err = os.Remove(filePath)
|
||||
if err != nil {
|
||||
log.Fatalln("旧文件删除失败", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/zu1k/nali/pkg/common"
|
||||
)
|
||||
|
||||
func Download(filePath string) (data []byte, err error) {
|
||||
@ -16,7 +18,7 @@ func Download(filePath string) (data []byte, err error) {
|
||||
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
|
||||
return
|
||||
}
|
||||
|
||||
common.ExistThenRemove(filePath)
|
||||
if err = ioutil.WriteFile(filePath, data, 0644); err == nil {
|
||||
log.Printf("已将最新的 纯真IP库 保存到本地: %s ", filePath)
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/zu1k/nali/pkg/common"
|
||||
|
||||
"github.com/saracen/go7z"
|
||||
)
|
||||
|
||||
@ -17,7 +19,7 @@ func Download(filePath string) (data []byte, err error) {
|
||||
log.Println("下载链接: https://www.zxinc.org/ip.7z")
|
||||
return
|
||||
}
|
||||
|
||||
common.ExistThenRemove(filePath)
|
||||
if err = ioutil.WriteFile(filePath, data, 0644); err == nil {
|
||||
log.Printf("已将最新的 ZX IPv6数据库 保存到本地: %s ", filePath)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user