diff --git a/cap.c b/cap.c index cc5f25e..e1dd178 100644 --- a/cap.c +++ b/cap.c @@ -20,8 +20,8 @@ char *command_result = NULL; // 执行命令的结果 #define CACHE_TTL 180 // 设定缓存的存活时间为 600 秒 (10 分钟) #define MAX_CACHE_SIZE 100 // 缓存最多存储 100 个 IP 地址 -struct ip_cache_node *ip_cache_head = NULL; // 缓存链表的头节点 -int cache_size = 0; // 当前缓存中的 IP 数量 +struct ip_cache_node *ip_cache_head = NULL; // 缓存链表的头节点 +int cache_size = 0; // 当前缓存中的 IP 数量 // 定义链表结构,用于缓存 IP 地址 struct ip_cache_node { @@ -127,7 +127,7 @@ void packet_handler(u_char *args, const struct pcap_pkthdr *header, const u_char const char *REGION_ENV = NULL; char ipset_query_command[256] = { 0 }; - char ip_query_command[256] = { 0 }; + //char ip_query_command[256] = { 0 }; // 定义 Response 结构体 Response response; @@ -181,22 +181,23 @@ void packet_handler(u_char *args, const struct pcap_pkthdr *header, const u_char char *p = curl_get_area(src_ip); - puts(p); + //puts(p); if (parse_json_to_struct(p, &response) == 0) { // 解析 JSON 到结构体 // 输出解析结果 + /* printf("Code: %s\n", response.code); printf("IP: %s\n", response.ip); printf("Continent: %s\n", response.data.continent); printf("Country: %s\n", response.data.country); printf("ISP: %s\n", response.data.isp); printf("Region: %s\n", response.data.region); - + */ char *p1 = strstr(response.continent_country, "中国"); if (p1 == NULL) { _printf(RED "%s %s\n" REDEND, src_ip, response.continent_country); r = add_ip_to_ipset(RULE_NAME, src_ip); - _printf("add_ip_to_ipset() return %d\n", r); + //_printf("add_ip_to_ipset() return %d\n", r); } } else { @@ -405,11 +406,11 @@ int main(int argc, char **argv) while (1) { - _printf("子进程当前 Ipset Rule 名 %s\n", RULE_NAME); + //_printf("子进程当前 Ipset Rule 名 %s\n", RULE_NAME); count = get_ip_count_in_ipset(RULE_NAME); if (count >= 0) { - _printf("IPSet %s 中的 IP 数量: %d\n", RULE_NAME, count); + _printf("子进程当前 Ipset Rule 名 %s, 数量: %d\n", RULE_NAME, count); if (count >= MAXIPSET && RULE_NAME_NUMBER <= MAXIPSET_RULT_NAME_NUM) // RULE_中的IP数量不超过MAXIPSET,并且集合不能超过 MAXIPSET_RULT_NAME_NUM 个 { RULE_NAME_NUMBER++; diff --git a/ip2region/a.out b/ip2region/a.out new file mode 100644 index 0000000..8afbd08 Binary files /dev/null and b/ip2region/a.out differ diff --git a/ip2region/a.out.valgrind b/ip2region/a.out.valgrind new file mode 100644 index 0000000..b96029a --- /dev/null +++ b/ip2region/a.out.valgrind @@ -0,0 +1,17 @@ +root@NIUYULING:/mnt/c/Users/root/Desktop/git.aixiao.me/DenyIP/ip2region# /usr/bin/valgrind --tool=memcheck --leak-check=full --show-reachable=yes --main-stacksize=8388608 --track-origins=yes ./a.out +==239839== Memcheck, a memory error detector +==239839== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. +==239839== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info +==239839== Command: ./a.out +==239839== +澳大利亚|0|0|0|0 +==239839== +==239839== HEAP SUMMARY: +==239839== in use at exit: 0 bytes in 0 blocks +==239839== total heap usage: 7 allocs, 7 frees, 534,473 bytes allocated +==239839== +==239839== All heap blocks were freed -- no leaks are possible +==239839== +==239839== For lists of detected and suppressed errors, rerun with: -s +==239839== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +root@NIUYULING:/mnt/c/Users/root/Desktop/git.aixiao.me/DenyIP/ip2region# \ No newline at end of file