gcc spam_ip.c -o spam_ip
c 데몬으로 실행하면 /tamp/spam_ip.txt 에 있는 ip를 읽어서 iptables 에 추가
=============================================================
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
pid_t pid, sid;
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
} else if (pid > 0) {
exit(EXIT_SUCCESS);
}
umask(0);
sid = setsid();
if (sid < 0) {
exit(EXIT_FAILURE);
}
if ((chdir("/")) < 0) {
exit(EXIT_FAILURE);
}
char string[255];
char cmd_buffer[255];
char *dirf="/tmp/spam_ip.txt";
FILE* fp;
while (1) {
fp=fopen(dirf,"r");
if(fp==NULL) {
// printf("no file n");
} else {
fscanf(fp,"%s",string);
printf("%sn",string);
fclose(fp);
sprintf(cmd_buffer, "/bin/ip_t %s", string);
system(cmd_buffer);
//return execl ("/bin/pwd", "pwd", NULL);
//execl("/bin/ls",%s,NULL);
unlink(dirf);
}
sleep(10);
}
exit(EXIT_SUCCESS);
}
===============================================================
gcc 파일명 -o 실행파일명
gcc aaa.c -o ip_drop
chmod 755 ip_drop
./ip_drop
|