diff --git a/blockip/.gitignore b/blockip/.gitignore index 7e80388..f936069 100644 --- a/blockip/.gitignore +++ b/blockip/.gitignore @@ -3,7 +3,6 @@ *.a *.so *.out -bip # 目录 obj/ diff --git a/blockip/bip b/blockip/bip new file mode 100644 index 0000000..fb258d3 Binary files /dev/null and b/blockip/bip differ diff --git a/blockip/include/stats.h b/blockip/include/stats.h index eb9fe08..fb88733 100644 --- a/blockip/include/stats.h +++ b/blockip/include/stats.h @@ -2,10 +2,14 @@ #define STATS_H #include "common.h" +#include /* 显示完整统计信息 */ void show_statistics(void); +/* 显示统计信息(支持动态监控) */ +void show_statistics_watch(bool watch_mode); + /* 显示活跃封禁列表 */ void show_active_bans(void); diff --git a/blockip/src/main.c b/blockip/src/main.c index 46ccf4d..c32dbf8 100644 --- a/blockip/src/main.c +++ b/blockip/src/main.c @@ -14,6 +14,7 @@ void show_help(void) { printf("--------------------------------------\n"); printf("使用方法:\n"); printf(" bip list 查看实时统计/活跃列表/日志\n"); + printf(" bip list -w/--watch 动态监控模式(每2秒刷新)\n"); printf(" bip show 显示本地持久化封禁列表\n"); printf(" bip add 手动封禁 IP (支持IPv4/IPv6/CIDR)\n"); printf(" 示例: 1.1.1.1 或 1.1.1.0/24 或 2001:db8::/32\n"); @@ -113,7 +114,11 @@ int main(int argc, char *argv[]) { /* list命令:显示统计信息 */ if (strcmp(command, "list") == 0) { - show_statistics(); + bool watch_mode = false; + if (argc >= 3 && (strcmp(argv[2], "-w") == 0 || strcmp(argv[2], "--watch") == 0)) { + watch_mode = true; + } + show_statistics_watch(watch_mode); return SUCCESS; } diff --git a/blockip/src/stats.c b/blockip/src/stats.c index e73afc5..786858e 100644 --- a/blockip/src/stats.c +++ b/blockip/src/stats.c @@ -254,3 +254,30 @@ void show_statistics(void) { log_show_recent(10); printf("\n"); } + +void show_statistics_watch(bool watch_mode) { + if (!watch_mode) { + show_statistics(); + return; + } + + /* 动态监控模式 */ + printf("\033[?25l"); /* 隐藏光标 */ + + while (1) { + printf("\033[2J\033[H"); /* 清屏并移到顶部 */ + + /* 显示时间戳 */ + time_t now = time(NULL); + struct tm *t = localtime(&now); + printf("%s[实时监控] 刷新时间: %04d-%02d-%02d %02d:%02d:%02d (按 Ctrl+C 退出)%s\n\n", + C_YELLOW, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec, C_RESET); + + show_statistics(); + + sleep(2); /* 每2秒刷新一次 */ + } + + printf("\033[?25h"); /* 恢复光标 */ +}