#include #include #include #include #include #include int CheckAndSave (const char* name, const char* extension); void panic (char* str); main (int argc, char* argv[] ) { if (argc!=3) { cout << "after4 " << endl; exit (0); } char *name = new char[30]; char *name1 = new char[100]; char *name2 = new char[100]; char *string = new char[100]; char *string2 = new char [100]; char *extension = new char[4]; extension = argv[1]; char *command = new char[100]; char *string1 = new char[101]; char *ptr; ofstream unsorted ("names_unsorted", ios::app); ofstream stat ("stat", ios::app); FILE* in = fopen (argv[2], "rw"); system ("wc -l stat >> dumb"); ifstream dumb ("dumb"); long StatOld; dumb >> StatOld; system ("rm dumb"); long cnt = 0; while (fgets(string,512,in)) { if (cnt++ < StatOld) continue; // ----------------- check pppd ------------------- sprintf (command, "ps -u root | grep pppd > dummy3"); system (command); ifstream dummy3 ("dummy3"); dummy3 >> string2; system ("rm dummy3"); if (strlen (string2) < 1) exit (0); // ------------------------------------------------- int n = (int) (strstr (string, " ") - string); int m = (int) (strstr (string, "\n") - string); if (n > 0) { strncpy (name, string, n); name[n] = '\0'; } else if (m > 0) { strncpy (name, string, m); name[m] = '\0'; } else panic ("Unable to determine end of line"); int result = CheckAndSave (name, extension); if (result > 0) { unsorted << name << endl; } stat << name << endl; strncpy (name, " ", 30); strncpy (name1, " ", 30); } stat.close (); unsorted.close(); fclose (in); // BubbleSort (); } // Check the name and add the name to the file int CheckAndSave (const char* name, const char* extension) { char *command = new char[200]; char *name1 = new char[100]; char *name2 = new char[100]; int a = 0; system ("rm dummy*"); sprintf (command, "lynx -dump %chttp://www.whois.corenic.net/cgi-bin/whois.cgi?query=%s.%s%c | grep %cis available%c > dummy", '"', name, extension, '"', '"', '"'); system (command); system ("wc -l dummy > dummy2"); ifstream dummy2 ("dummy2"); dummy2 >> a; dummy2.close(); delete (command); return a; } void panic (char* str) { cout << str << endl; exit (0); }