增加 -l 选项打印 iptales 规则
This commit is contained in:
Binary file not shown.
35
cap.c
35
cap.c
@@ -203,12 +203,13 @@ void usage()
|
|||||||
puts("MAIL: aixiao@aixiao.me");
|
puts("MAIL: aixiao@aixiao.me");
|
||||||
puts("Date: 20241024");
|
puts("Date: 20241024");
|
||||||
puts(" Usage: denyip [-d] [-i <interface>] [-s <start|stop>] [-h|-?]");
|
puts(" Usage: denyip [-d] [-i <interface>] [-s <start|stop>] [-h|-?]");
|
||||||
puts(" -d Daemon mode");
|
puts(" -d --daemon Daemon mode");
|
||||||
puts(" -i interface (default eth0)");
|
puts(" -i --interface interface (default eth0)");
|
||||||
puts(" -s regular signal (default start|stop) ");
|
puts(" -l print iptables rule");
|
||||||
puts(" start Enable Iptables rule");
|
puts(" -s --signal regular signal (default start|stop) ");
|
||||||
puts(" stop Disable Iptables rule");
|
puts(" start Enable Iptables rule");
|
||||||
puts(" -h|-? Help Information");
|
puts(" stop Disable Iptables rule");
|
||||||
|
puts(" -h|-? Help Information");
|
||||||
puts("");
|
puts("");
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -269,8 +270,19 @@ int main(int argc, char **argv)
|
|||||||
memset(&device, 0, sizeof(device));
|
memset(&device, 0, sizeof(device));
|
||||||
memset(errbuf, 0, PCAP_ERRBUF_SIZE);
|
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) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
if (daemon(1, 1)) {
|
if (daemon(1, 1)) {
|
||||||
@@ -280,6 +292,10 @@ int main(int argc, char **argv)
|
|||||||
case 'i':
|
case 'i':
|
||||||
strcpy(interface, optarg);
|
strcpy(interface, optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
system("iptables -L -v -n --line-numbers");
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (strcmp(optarg, "start") == 0) {
|
if (strcmp(optarg, "start") == 0) {
|
||||||
memset(Ipset_Command, 0, BUFFER);
|
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);
|
shmid = shmget(SHM_KEY, SHM_SIZE, IPC_CREAT | 0666);
|
||||||
|
|||||||
1
cap.h
1
cap.h
@@ -15,6 +15,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "ip2region/ip2region.h"
|
#include "ip2region/ip2region.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user