import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FileDownloader {
// 你的下载 token
private static final String TOKEN = "your_token_here"; // 替换为实际的 token
// 文件列表
private static final String[] FILES = {
"ipv4-qx.mmdb",
"ipv4-cs.mmdb",
"ipv6-qx.mmdb",
"ipv6-cs.mmdb"
};
// 下载目录
private static final String DOWNLOAD_DIR = "downloaded_files";
// 基础 URL 模板
private static final String BASE_URL = "https://www.ipdb360.com/download/%s/%s";
public static void main(String[] args) {
// 创建下载目录
Path downloadDir = Paths.get(DOWNLOAD_DIR);
try {
Files.createDirectories(downloadDir);
} catch (IOException e) {
System.err.println("创建目录失败: " + e.getMessage());
return;
}
// 遍历文件并下载
for (String file : FILES) {
try {
downloadFile(file, TOKEN);
} catch (IOException e) {
System.err.println("下载 " + file + " 失败: " + e.getMessage());
}
}
}
private static void downloadFile(String fileName, String token) throws IOException {
// 构造下载 URL
String urlString = String.format(BASE_URL, token, fileName);
URL url = new URL(urlString);
// 建立连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
// 检查响应状态
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("下载失败,状态码: " + responseCode);
}
// 构造本地文件路径
Path localPath = Paths.get(DOWNLOAD_DIR, fileName);
// 下载文件
try (InputStream inputStream = connection.getInputStream();
OutputStream outputStream = Files.newOutputStream(localPath)) {
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
System.out.println("成功下载: " + fileName);
// 关闭连接
connection.disconnect();
}
}
package main
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
)
// 你的下载 token
const token = "your_token_here" // 替换为实际的 token
// 文件列表
var files = []string{
"ipv4-qx.mmdb",
"ipv4-cs.mmdb",
"ipv6-qx.mmdb",
"ipv6-cs.mmdb",
}
// 下载目录
const downloadDir = "downloaded_files"
// 基础 URL 模板
const baseURL = "https://www.ipdb360.com/download/%s/%s"
func downloadFile(fileName, token string) error {
// 构造下载 URL
url := fmt.Sprintf(baseURL, token, fileName)
// 构造本地文件路径
localPath := filepath.Join(downloadDir, fileName)
// 创建下载目录(如果不存在)
if err := os.MkdirAll(downloadDir, 0755); err != nil {
return fmt.Errorf("创建目录失败: %v", err)
}
// 发送 HTTP GET 请求
resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("请求失败: %v", err)
}
defer resp.Body.Close()
// 检查响应状态
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("下载失败,状态码: %d", resp.StatusCode)
}
// 创建本地文件
file, err := os.Create(localPath)
if err != nil {
return fmt.Errorf("创建文件失败: %v", err)
}
defer file.Close()
// 将响应内容写入文件
_, err = io.Copy(file, resp.Body)
if err != nil {
return fmt.Errorf("写入文件失败: %v", err)
}
fmt.Printf("成功下载: %s\n", fileName)
return nil
}
func main() {
for _, file := range files {
if err := downloadFile(file, token); err != nil {
fmt.Printf("下载 %s 失败: %v\n", file, err)
}
}
}
<?php
// 你的下载 token
$token = "your_token_here"; // 替换为实际的 token
// 文件列表
$files = [
"ipv4-qx.mmdb",
"ipv4-cs.mmdb",
"ipv6-qx.mmdb",
"ipv6-cs.mmdb"
];
// 下载目录
$downloadDir = "downloaded_files";
// 基础 URL 模板
$baseUrl = "https://www.ipdb360.com/download/{$token}/";
// 创建下载目录(如果不存在)
if (!is_dir($downloadDir)) {
mkdir($downloadDir, 0755, true);
}
function downloadFile($url, $localPath) {
// 初始化 cURL
$ch = curl_init($url);
$fp = fopen($localPath, 'wb');
if ($fp === false) {
echo "无法创建文件: $localPath\n";
return false;
}
// 设置 cURL 选项
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// 执行下载
$result = curl_exec($ch);
// 检查是否成功
if ($result === false) {
echo "下载失败: $url, 错误: " . curl_error($ch) . "\n";
} else {
echo "成功下载: $localPath\n";
}
// 清理
curl_close($ch);
fclose($fp);
return $result;
}
// 遍历文件并下载
foreach ($files as $file) {
$url = $baseUrl . $file;
$localPath = $downloadDir . DIRECTORY_SEPARATOR . $file;
downloadFile($url, $localPath);
}
?>
import requests
import os
# 你的下载 token
token = "your_token_here" # 替换为实际的 token
# 文件列表 根据需求自己调整
files = [
# "ipv4-qx.mmdb",
# "ipv4-cs.mmdb",
# "ipv6-qx.mmdb",
# "ipv6-cs.mmdb"
]
# 下载 URL 模板
base_url = "https://www.ipdb360.com/download/{token}/{fileName}"
# 下载目录(可以根据需要修改)
download_dir = "downloaded_files"
# 创建下载目录(如果不存在)
if not os.path.exists(download_dir):
os.makedirs(download_dir)
def download_file(file_name, token):
# 构造下载 URL
url = base_url.format(token=token, fileName=file_name)
# 构造本地文件路径
local_path = os.path.join(download_dir, file_name)
try:
# 发送 GET 请求
response = requests.get(url, stream=True)
# 检查响应状态
if response.status_code == 200:
# 以二进制写入文件
with open(local_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
print(f"成功下载: {file_name}")
else:
print(f"下载失败: {file_name}, 状态码: {response.status_code}")
except Exception as e:
print(f"下载 {file_name} 时出错: {str(e)}")
# 遍历文件列表并下载
for file_name in files:
download_file(file_name, token)
#!/bin/bash
# 你的下载 token
TOKEN="your_token_here" # 替换为实际的 token
# 文件列表 根据需求自己调整
FILES=(
# "ipv4-qx.mmdb"
# "ipv4-cs.mmdb"
# "ipv6-qx.mmdb"
# "ipv6-cs.mmdb"
)
# 下载目录
DOWNLOAD_DIR="downloaded_files"
# 创建下载目录(如果不存在)
mkdir -p "$DOWNLOAD_DIR"
# 基础 URL 模板
BASE_URL="https://www.ipdb360.com/download/$TOKEN"
# 遍历文件并下载
for FILE in "${FILES[@]}"; do
echo "正在下载: $FILE"
curl -o "$DOWNLOAD_DIR/$FILE" "$BASE_URL/$FILE"
if [ $? -eq 0 ]; then
echo "成功下载: $FILE"
else
echo "下载失败: $FILE"
fi
done