//arp cache mantainer by radix //radix (at) ironik.org #include #include #include main(int argc, char *argv[]) { char ping[30], arp[30], info[60], graph[50]; int f=0, r=0, t=0,g; float perc; FILE *pd; if(argc < 2) { printf("usage %s gateway [ping_target]\nyou can specify other ping target if you don't want to use the gateway\n\n", argv[0]); exit(1); } sprintf(arp, "arp -d %s", argv[1]); sprintf(ping, "ping -t %s", argv[argc-1]); pd = popen(ping, "r"); for(g=0;g < 48; g++) graph[g]=' '; graph[48] = '\0'; g=0; while(!feof(pd)) { if(fgetc(pd) =='R') if(fgetc(pd)=='e') { if(fgetc(pd)=='q') { f++; if(g>47) {for(g=0;g < 48; g++) graph[g]=' '; g=0;} graph[g] = 'x'; system(arp); } else { r++; if(g>47) {for(g=0;g < 48; g++) graph[g]=' '; g=0;} graph[g] = (char)2; } g++;t++; perc = r * 100.00 / t; system("clear"); sprintf(info,"[total: %d] [replies: %d (%.1f%%)] [timeouts: %d (%.1f%%)", t, r, perc, f, 100-perc ); printf("%s",info); for(perc=1;perc < (60 - strlen(info)); perc++) putchar(' '); printf("]\n"); printf("[history: %s ]\n", graph); } } }