优化
This commit is contained in:
Binary file not shown.
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -21,7 +21,7 @@ type IPInfo struct {
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
log.Fatalf("Usage: %s <IP>", os.Args[0])
|
||||
log.Fatalf("用法: %s <IP>", os.Args[0])
|
||||
}
|
||||
|
||||
// 目标 URL
|
||||
@@ -30,23 +30,22 @@ func main() {
|
||||
// 发送 GET 请求
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
log.Fatalf("Error making GET request: %v", err)
|
||||
log.Fatalf("发送 GET 请求时出错: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 读取响应体
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading response body: %v", err)
|
||||
log.Fatalf("读取响应体时出错: %v", err)
|
||||
}
|
||||
|
||||
// 解析 JSON 数据
|
||||
var ipInfo IPInfo
|
||||
if err := json.Unmarshal(body, &ipInfo); err != nil {
|
||||
log.Fatalf("Error parsing JSON: %v", err)
|
||||
log.Fatalf("解析 JSON 时出错: %v", err)
|
||||
}
|
||||
|
||||
// 提取并打印 continent 和 country 字段
|
||||
fmt.Printf("%s%s\n", ipInfo.Data.Continent, ipInfo.Data.Country)
|
||||
|
||||
}
|
||||
|
||||
22
main.c
22
main.c
@@ -1,24 +1,4 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/resource.h>
|
||||
#include <signal.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#include "ip2region.h"
|
||||
#include "qqwry.h"
|
||||
#include "common.h"
|
||||
|
||||
#define RED "\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
#define WHITELIST_IP_NUM 1024
|
||||
#define MAXIPSET 65534
|
||||
|
||||
char *xdb_path = "ip2region.xdb";
|
||||
pid_t pid1, pid2; // 保存子进程的 PID
|
||||
#include "main.h"
|
||||
|
||||
|
||||
int is_valid_ip(const char *ip)
|
||||
|
||||
26
main.h
Normal file
26
main.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_h
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/resource.h>
|
||||
#include <signal.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#include "ip2region.h"
|
||||
#include "qqwry.h"
|
||||
#include "common.h"
|
||||
|
||||
#define RED "\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
#define WHITELIST_IP_NUM 1024
|
||||
#define MAXIPSET 65534
|
||||
|
||||
char *xdb_path = "ip2region.xdb";
|
||||
pid_t pid1, pid2; // 保存子进程的 PID
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user