新增MD文件
This commit is contained in:
47
README.md
Normal file
47
README.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# denyip
|
||||||
|
|
||||||
|
大陆服务器禁止国外IP访问
|
||||||
|
|
||||||
|
## build
|
||||||
|
|
||||||
|
~~~bash
|
||||||
|
# Debian System
|
||||||
|
apt install build-essential
|
||||||
|
apt install golang
|
||||||
|
apt install tcpdump procps iptables ipset
|
||||||
|
|
||||||
|
root@NIUYULING:/mnt/c/Users/root/Desktop/git.aixiao.me/DenyIP# make clean; make
|
||||||
|
rm -rf denyip ipquery
|
||||||
|
rm -rf main.o common.o ip2region/ip2region.o ip2region/xdb_searcher.o qqwry/qqwry.o
|
||||||
|
gcc -g -Os -Wall -Iip2region -Iqqwry -c main.c -o main.o
|
||||||
|
gcc -g -Os -Wall -Iip2region -Iqqwry -c common.c -o common.o
|
||||||
|
gcc -g -Os -Wall -Iip2region -Iqqwry -c ip2region/ip2region.c -o ip2region/ip2region.o
|
||||||
|
gcc -g -Os -Wall -Iip2region -Iqqwry -c ip2region/xdb_searcher.c -o ip2region/xdb_searcher.o
|
||||||
|
gcc -g -Os -Wall -Iip2region -Iqqwry -c qqwry/qqwry.c -o qqwry/qqwry.o
|
||||||
|
gcc -g -Os -Wall -Iip2region -Iqqwry -o denyip main.o common.o ip2region/ip2region.o ip2region/xdb_searcher.o qqwry/qqwry.o -lm -static
|
||||||
|
root@NIUYULING:/mnt/c/Users/root/Desktop/git.aixiao.me/DenyIP#
|
||||||
|
~~~
|
||||||
|
|
||||||
|
### help
|
||||||
|
|
||||||
|
~~~bash
|
||||||
|
|
||||||
|
root@NIUYULING:/mnt/c/Users/root/Desktop/git.aixiao.me/DenyIP# ./denyip -h
|
||||||
|
DenyIp
|
||||||
|
Linux system firewall, reject non-Chinese IP
|
||||||
|
Email: aixiao@aixiao.me
|
||||||
|
Version: 0.1
|
||||||
|
Usage: ./denyip [-i eth0|-h|-?] [start|stop]
|
||||||
|
Options:
|
||||||
|
stop Enable firewall rules
|
||||||
|
start Disable firewall rules
|
||||||
|
Parameters:
|
||||||
|
-h|? Help info
|
||||||
|
-i interface name
|
||||||
|
|
||||||
|
|
||||||
|
root@niuyuling:~/DenyIP# killall denyip # 关闭
|
||||||
|
root@niuyuling:~/DenyIP# ./denyip -i eth0 # 启动
|
||||||
|
root@niuyuling:~/DenyIP# ./denyip start # Iptables 规则打开
|
||||||
|
root@niuyuling:~/DenyIP# ./denyip stop # Iptables 规则关闭
|
||||||
|
~~~
|
||||||
3
main.c
3
main.c
@@ -307,7 +307,7 @@ int main(int argc, char *argv[])
|
|||||||
perror("popen failed");
|
perror("popen failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建足够大的缓冲区来存储命令输出
|
// 创建足够大的缓冲区来存储命令输出
|
||||||
char buffer[1024 * 2]; // 2KB 缓冲区
|
char buffer[1024 * 2]; // 2KB 缓冲区
|
||||||
size_t bytesRead = fread(buffer, 1, sizeof(buffer) - 1, fp);
|
size_t bytesRead = fread(buffer, 1, sizeof(buffer) - 1, fp);
|
||||||
@@ -349,6 +349,7 @@ int main(int argc, char *argv[])
|
|||||||
iteration++;
|
iteration++;
|
||||||
|
|
||||||
if (iteration >= 3600) {
|
if (iteration >= 3600) {
|
||||||
|
iteration = 0;
|
||||||
printf("准备重启进程...\n");
|
printf("准备重启进程...\n");
|
||||||
restart_process(pid1, pid2, argv);
|
restart_process(pid1, pid2, argv);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user