This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
*.a
|
||||
*.so
|
||||
*.out
|
||||
bip
|
||||
|
||||
# 目录
|
||||
obj/
|
||||
|
||||
BIN
Binary file not shown.
@@ -2,10 +2,14 @@
|
||||
#define STATS_H
|
||||
|
||||
#include "common.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
/* 显示完整统计信息 */
|
||||
void show_statistics(void);
|
||||
|
||||
/* 显示统计信息(支持动态监控) */
|
||||
void show_statistics_watch(bool watch_mode);
|
||||
|
||||
/* 显示活跃封禁列表 */
|
||||
void show_active_bans(void);
|
||||
|
||||
|
||||
+6
-1
@@ -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> 手动封禁 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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"); /* 恢复光标 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user