#include #include #include #define CMD "/sbin/ipchains" #define WAITTIME 60 #define WAITINTERVAL 3 void execchain(const char* cmd, const char* host); void openport(const char* host); void closeport(const char* host); void wait(); int main(int argc, char *argv[]) { char *host; if (argc < 2) return -1; host = argv[1]; openport(host); wait(); closeport(host); return 0; } void execchain(const char* cmd, const char* host) { char cb[256 * 2 + 1]; snprintf(cb, sizeof(cb), CMD " %s Cdynamic -p tcp -s %s --dport 22 -j ACCEPT", cmd, host); cb[sizeof(cb)-1] = '\0'; printf("EXEC: %s\n", cb); system(cb); } void openport(const char* host) { execchain("-A", host); } void closeport(const char* host) { execchain("-D", host); } void wait() { int s; // print header printf("|"); for (s = 0; s < WAITTIME; s += WAITINTERVAL) { printf("-"); } printf("|\n"); // インジケータ printf("|"); fflush(stdout); for (s = 1; s <= WAITTIME; ++s) { if (!(s % WAITINTERVAL)) { printf("*"); fflush(stdout); } sleep(1); } printf("|\n"); }