gods

a simple blocklist for ssh
Log | Files | Refs | README | LICENSE

fw.c (545B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 int
      6 fw_block(char *ip)
      7 {
      8 	/* pfctl -t blacklist -T add 123.123.123.123  */
      9 	char s[43] = "pfctl -t blacklist -T add ";
     10 
     11 	fprintf(stderr, "fw_block: blocked ip: %s\n", ip);
     12 	strcat(s, ip);
     13 	if (system(s) == 127)
     14 		return 0;
     15 	return 1;
     16 }
     17 
     18 int
     19 fw_unblock(char *ip)
     20 {
     21 	/* pfctl -t blacklist -T delete 123.123.123.123  */
     22 	char s[46] = "pfctl -t blacklist -T delete ";
     23 
     24 	fprintf(stderr, "fw_unblock: unblocked ip: %s\n", ip);
     25 	strcat(s, ip);
     26 	if (system(s) == 127)
     27 		return 0;
     28 	return 1;
     29 }