Click here to Skip to main content
15,895,084 members

Telnet client using TCP

mikhilv asked:

Open original thread
Hi friends ,

I am willing to connect to linux system from windows & execute some commands on it . I am writting tcp program which will take telnet of linux machine & excute commands on it . I am connecting on port 23 successfully . but Sever sends me something junk value as ²↑ ² ²# ²' . I dont understand what it is exactly .When I sends telnet command as
MIDL
strcpy(lv_send_buffer,"telnet 111.1.112.11 -l user");
	lv_NoOfBytes = send(lv_clientSocket,lv_send_buffer,strlen(lv_send_buffer),0); 

Server does not sends anything . Please guide me how can I send username / password through program & execute commands on it .
Code is as follow .. Thanks ...

int main()
{
	char lv_recv_buffer[512]	=	{""};
	char lv_send_buffer[256]	=	{""};
	int lv_ret		=		0;
	int lv_clientSocket = -1 ;
	struct sockaddr_in lv_clientAddr ; 
	struct hostnet *lp_host ;
	int lv_NoOfBytes		=	-1	;
	WSADATA	lv_wsdata ;		
	lv_ret = WSAStartup(0x0101,&lv_wsdata);
	if (lv_ret != 0 )
	{
		return (0);
	}
	lv_clientSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); 
	
	if (lv_clientSocket == -1 )
	{
		printf("socket creation failed");
		WSACleanup();
		return 0 ;
	}
	else
	{
		printf("socket creation success");
	}

	lv_clientAddr.sin_family = AF_INET ;
	lv_clientAddr.sin_addr.s_addr = inet_addr("192.9.202.31");
	lv_clientAddr.sin_port=htons(23);
	
	if (connect(lv_clientSocket, (struct sockaddr *) &lv_clientAddr,sizeof(lv_clientAddr)))
	{
		int lv_err = WSAGetLastError();
		printf("error while connecting [%d] ",lv_err);
		return 0 ;
	}
	else
	{
		printf("connection success");
	}
	
	strcpy(lv_send_buffer,"telnet 111.1.112.11 -l user");
	
	
	lv_NoOfBytes = recv(lv_clientSocket,lv_recv_buffer,512,0);
	if (lv_NoOfBytes <=0 )
	{
		printf("no data received ");
		closesocket(lv_clientSocket);
		WSACleanup();
	}
	else
	{
		printf("from server :[%s] ",lv_recv_buffer);
	}

	lv_NoOfBytes = send(lv_clientSocket,lv_send_buffer,strlen(lv_send_buffer),0);
	printf("bytes send [%d]",lv_NoOfBytes );

	memset( lv_recv_buffer,0,sizeof(lv_recv_buffer));
	Sleep(1000);
	while(1)
	{
		lv_NoOfBytes = recv(lv_clientSocket,lv_recv_buffer,512,0);
		if (lv_NoOfBytes <=0 )
		{
			printf("no data received ");
			closesocket(lv_clientSocket);
			WSACleanup();
		}
		else
		{
			printf("from server :[%s] ",lv_recv_buffer);
		}
	}
			
		getch();
	return  0;

}
Tags: C++, Linux

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900