Thread: telnet

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    40

    Question telnet

    Im making a little app to use at work when i have multipile emails to delete. since the email server I log on to to delete the emails doesnt have a delete all command i have to do it manualy

    dele 1
    dele 2
    ...

    this is painful when you have 2000 to delete. im gonna make a loop with the ++ increment thingy.

    my problem stoping me from going forward is how to make it execute that in a 3rd party app like telnet. how to make it that it logs in telnet with a username and pass and then execute my loop in telenet is whats troubling me.

    Any ideas?

  2. #2
    CALVIN
    Guest

    try rsh or expect

    I would recommend you to use rsh to do so. If you really want to use telnet, you may need expect to control the session.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    well i know how to do it in bash. but the thing is if i would make such a script, only I would have access to it. I want to make it so that all my collegues can use it also.
    cout << "Gotta love cpp\n";
    cout << "UIN: 825265\n";
    cout << "[email protected]\n;
    /* Hope I can know enough one
    day to make my very own notepad
    */

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    g++ -o popdel popdel.cpp
    /usr/include/netdb.h: In function `int main(int, char**)':
    /usr/include/netdb.h:137: too few arguments to function `hostent* gethostbyaddr(const void*, unsigned int, int)'
    popdel.cpp:20: at this point in file
    popdel.cpp:65: invalid conversion from `const char*' to `unsigned int'
    popdel.cpp:65: invalid conversion from `int' to `const char*'

    hehe im haing fun trying to debug this hehehe.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    nice. it compiled without error. only problem is it doesnt work. it connects then after a momments it says done. and exits

    Problem is that mail server is quit gay. when u login it will say

    +OK b1gprt49 is welcome here

    thats after sending user and pass.

    To see how many msg i must send the list command first

    list
    +OK 2 messages
    1 1274
    2 1271
    .

    Im sure if we can squeez list in there it will work like charm

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    sorry man my bad. well it seem to be deleting something in background. but I think i found out why it doesnt acctualy work.

    the problem is how the program exits. it doesnt send the QUIT string to the daemon. causing it to rset. I told u this server was gay lol.

    close( s );
    puts( "Done." );
    return 0;

    How would i translate that to become quit

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    man this works perfectly. thanks man. I wouldnt have done it without you.

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    to make this a port for dos. do i do this
    from:
    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    to:
    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/winsock.h
    #include <netdb.h>

    where would i shove WSAStartup cause i have no clue how to use sockets in win32

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    does this look right to you?

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <winsock.h>
    
    
    int main( int argc, char *argv[] )
    {
      char               buf[128];
      int                i,
                         s;
      struct sockaddr_in server;
      WSADATA wsa;
      if( WSAStartup( MAKEWORD( 1, 1 ), &wsa ) ) {
      perror( "Startup" );
      return 1;
      }
      struct hostent    *h;
    
      if( argc != 4 ) {
        fprintf( stderr, "Usage: ./prog server user password\n" );
        return 1;
    
    ......

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    why are you so good man? how long have you been at this hehe

  11. #11
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    oups

    --------------------Configuration: popdel32 - Win32 Debug--------------------
    Compiling...
    popdel32.cpp
    c:\cpp\popdel32.cpp(40) : error C2065: 'snprintf' : undeclared identifier
    c:\cpp\popdel32.cpp(42) : error C2065: 'close' : undeclared identifier
    Error executing cl.exe.

    popdel32.exe - 2 error(s), 0 warning(s)

    this is lines 40 to 44

    snprintf( buf, 128, "USER %s\r\n", argv[2] );
    if( send( s, buf, strlen( buf ), 0 ) == -1 ) {
    perror( "send" ), close( s );
    return 1;
    }

    Im using visual c++ 6.0 enterprise to compile it.
    now im lost hehe

  12. #12
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    hehe i did change it. now im getting errors when linking.

    here is my code at this state. the error msg of the compiler (visual c++ 6) is under the code

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <winsock.h>
    
    
    int main( int argc, char *argv[] )
    {
      char               buf[128];
      int                i,
                         s;
      struct sockaddr_in server;
      WSADATA wsa;
      if( WSAStartup( MAKEWORD( 1, 1 ), &wsa ) ) {
      perror( "Startup" );
      return 1;
      }
      struct hostent    *h;
    
      if( argc != 4 ) {
        fprintf( stderr, "Usage: ./prog server user password\n" );
        return 1;
      }
      if( ( h = gethostbyname( argv[1] ) ) == NULL ) {
        perror( "gethostbyaddr" );
        return 1;
      }
      server.sin_addr = *( struct in_addr* )h->h_addr_list[0];
      server.sin_port = htons( 110 );
      server.sin_family = AF_INET;
      s = socket( AF_INET, SOCK_STREAM, 0 );
      if( s < 0 ) {
        perror( "socket" );
        return 1;
      }
      if( connect( s, ( struct sockaddr* )&server, sizeof( struct sockaddr ) 
    ) < 0 ) {
        perror( "connect" );
        return 1;
      }
      sprintf( buf, "USER %s\r\n", argv[2] );
      if( send( s, buf, strlen( buf ), 0 ) == -1 ) {
        perror( "send" ), closesocket( s );
        return 1;
      }
      if( ( i = recv( s, buf, 128, 0 ) ) == -1 ) {
        perror( "recv" ), closesocket( s );
        return 1;
      }
      if( strncmp( buf, "+OK", 3 ) != 0 ) {
        buf[i] = 0;
        fprintf( stderr, "``%s''\n", buf ), closesocket( s );
        return 1; }
      sprintf( buf, "PASS %s\r\n", argv[3] );
      if( send( s, buf, strlen( buf ), 0 ) == -1 ) {
        perror( "send" ), closesocket( s );
        return 1;
      }
      if( ( i = recv( s, buf, 128, 0 ) ) == -1 ) {
        perror( "recv" );
        return 1;
      }
      if( strncmp( buf, "+OK", 3 ) != 0 ) {
        buf[i] = 0;
        fprintf( stderr, "``%s''\n", buf );
      }
    
      for( i = 1; ; ++i ) {
    	sprintf( buf, "DELE %d\r\n", i );
        if( send( s, buf, strlen( buf ), 0 ) == -1 ) {
          perror( "Sending DELE" );
          closesocket( s );
          return 1;
        }
        if( recv( s, buf, 128, 0 ) == -1 ) {
          perror( "Waiting for DELE answer" );
          closesocket( s );
          return 1;
        }
        if( strncmp( buf, "+OK", 3 ) != 0 )
          break;
      }
      send( s, "QUIT\r\n", 6, 0 );
      closesocket( s );
      puts( "Done." );
      return 0;
    }
    --------------------Configuration: popdel32 - Win32 Debug--------------------
    Compiling...
    popdel32.cpp
    Linking...
    popdel32.obj : error LNK2001: unresolved external symbol _recv@16
    popdel32.obj : error LNK2001: unresolved external symbol _closesocket@4
    popdel32.obj : error LNK2001: unresolved external symbol _send@16
    popdel32.obj : error LNK2001: unresolved external symbol _connect@12
    popdel32.obj : error LNK2001: unresolved external symbol _socket@12
    popdel32.obj : error LNK2001: unresolved external symbol _htons@4
    popdel32.obj : error LNK2001: unresolved external symbol _gethostbyname@4
    popdel32.obj : error LNK2001: unresolved external symbol _WSAStartup@8
    Debug/popdel32.exe : fatal error LNK1120: 8 unresolved externals
    Error executing link.exe.

    popdel32.exe - 9 error(s), 0 warning(s)

    What causes this

  13. #13
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    any idea?
    cout << "Gotta love cpp\n";
    cout << "UIN: 825265\n";
    cout << "[email protected]\n;
    /* Hope I can know enough one
    day to make my very own notepad
    */

  14. #14
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    why is visual c++ 6.0 giving me those errors while its linking?

    look 2 posts up ^

  15. #15
    Registered User
    Join Date
    Feb 2002
    Posts
    40
    lol indeed i read your post but i figured you were using visual c++.

    your most probably a unix dude

    But i can compile it with what ever. I have borland 5.5, devc++, visual 6.0, DJGPP, etc..

    just tell me what to tweak to compile without error in any of win32 compilers hehe.

    If we cant make it a win32 port then i can use the unix version and make a perl script execute it from the web and use it like that. that can do the same job. but a dos version would have been fun

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with telnet and tcp
    By hoAx in forum Windows Programming
    Replies: 11
    Last Post: 03-11-2008, 02:03 PM
  2. C Function Telnet Email
    By karcheee in forum C Programming
    Replies: 3
    Last Post: 07-25-2005, 11:39 AM
  3. C Execl Telnet
    By karcheee in forum C Programming
    Replies: 1
    Last Post: 04-26-2005, 02:31 PM
  4. telnet!!
    By bigB8210 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-13-2003, 05:09 PM
  5. Most Secure (SSH) Telnet Client for Programming
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 02-14-2002, 08:49 PM