增加 -l 选项打印 iptales 规则

This commit is contained in:
2024-11-04 16:49:00 +08:00
parent 9f8f19dbfe
commit e3509c3152
6 changed files with 29 additions and 7 deletions

Binary file not shown.

29
cap.c
View File

@@ -203,9 +203,10 @@ void usage()
puts("MAIL: aixiao@aixiao.me");
puts("Date: 20241024");
puts(" Usage: denyip [-d] [-i <interface>] [-s <start|stop>] [-h|-?]");
puts(" -d Daemon mode");
puts(" -i interface (default eth0)");
puts(" -s regular signal (default start|stop) ");
puts(" -d --daemon Daemon mode");
puts(" -i --interface interface (default eth0)");
puts(" -l print iptables rule");
puts(" -s --signal regular signal (default start|stop) ");
puts(" start Enable Iptables rule");
puts(" stop Disable Iptables rule");
puts(" -h|-? Help Information");
@@ -269,8 +270,19 @@ int main(int argc, char **argv)
memset(&device, 0, sizeof(device));
memset(errbuf, 0, PCAP_ERRBUF_SIZE);
int longindex = 0;
char optstring[] = "di:s:lh?";
static struct option longopts[] = {
{ "interface", required_argument, 0, 'i' },
{ "signal", required_argument, 0, 's' },
{ "daemon", no_argument, 0, 'd' },
{ "l", no_argument, 0, 'l' },
{ "help", no_argument, 0, 'h' },
{ "?", no_argument, 0, '?' },
{ 0, 0, 0, 0 }
};
while ((opt = getopt(argc, argv, "di:s:h?")) != -1) {
while (-1 != (opt = getopt_long(argc, argv, optstring, longopts, &longindex))) {
switch (opt) {
case 'd':
if (daemon(1, 1)) {
@@ -280,6 +292,10 @@ int main(int argc, char **argv)
case 'i':
strcpy(interface, optarg);
break;
case 'l':
system("iptables -L -v -n --line-numbers");
exit(0);
break;
case 's':
if (strcmp(optarg, "start") == 0) {
memset(Ipset_Command, 0, BUFFER);
@@ -319,6 +335,11 @@ int main(int argc, char **argv)
}
}
if (strcmp(interface, "eth0") != 0)
{
}
// 创建共享内存
shmid = shmget(SHM_KEY, SHM_SIZE, IPC_CREAT | 0666);

1
cap.h
View File

@@ -15,6 +15,7 @@
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include "ip2region/ip2region.h"

BIN
cap.o

Binary file not shown.

BIN
common.o

Binary file not shown.

BIN
denyip

Binary file not shown.