Click here to Skip to main content
15,892,809 members
Articles / Desktop Programming / MFC

Telnet Console Application

Rate me:
Please Sign up or sign in to vote.
4.96/5 (18 votes)
31 Jul 2001 279K   9.3K   63  
A console based telnet application.
#include "stdafx.h"
#include <windows.h>
#include <winsock.h>
#include <process.h>
#include "SocketRx.h"
#include "SocketDx.h"
#include "SocketTx.h"
#include <conio.h>
#include "Telnet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CWinApp theApp;
using namespace std;
HANDLE stdin1;
HANDLE hHeap1;
HANDLE stdout1;
HANDLE stderr1;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRet;
WSADATA wd;
int nPort;
char strIP[256];
char strTitle[256];
SOCKET hSocket;
HANDLE hThread[2];

	nRet = AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
	if ( nRet == FALSE )
	{
		printf("\nAfxWinInit Fail..............!\n");
		return 0;
	}

	nPort = IPPORT_TELNET;
	SetConsoleTitle("Try To connect...");
  	WSAStartup(0x0101,&wd);
    
	stdin1 = GetStdHandle(STD_INPUT_HANDLE);
	stdout1 = GetStdHandle(STD_OUTPUT_HANDLE);
	stderr1 = GetStdHandle(STD_ERROR_HANDLE);
	hHeap1 = GetProcessHeap();
	SetConsoleMode(stdin1,ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
	
	printf("\nPlease Enter IP/Domain.........:");
	scanf("%s",strIP);
	if ( strlen(strIP) < 3 ) { printf("\nBad IP/Domain\n"); getch(); return 0; }
	printf("\nPort...........%d :",nPort);
	
	CSocketDx	SocketDx(strIP,nPort);
	hSocket = SocketDx.TelnetConnect();
	if ( hSocket == NULL ) { printf("\nUnable To Connect\n");getche(); return 0; }

	CSocketRx	SocketRx(hSocket,hThread[0]); 
	CSocketTx	SocketTx(hSocket,hThread[1]);

	wsprintf(strTitle,"Connecting to %s:%d",strIP,nPort);
	SetConsoleTitle(strTitle);

	WaitForMultipleObjects(2,hThread,FALSE,INFINITE);
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Pakistan Pakistan
Master of Computer Science
Experince
1). C++
2). C
3). Network Programming...
Socket,Pipe,Protocol Implemntation
4). hardware interfaceing
5). Emabeded programming in C51...Etc
(for 8051,PIC,C166 Processores)


Comments and Discussions