#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <netdb.h>
#include <ctype.h>
#include <fcntl.h>
#include "fTelnet.h"
int main(argc,argv)
int argc;
char **argv;
{
char strBuff[256];
char szRecBuff[256];
int socClient;
char szCmdText[16];
char ErrorMessage[100];
struct sockaddr_in SerAddress;
int i;
int j;
int nRtn;
memset(strBuff,0X00,sizeof(strBuff));
InitTelnetClientState();
/*dms 130.76.23.250*/
/*axe 10.156.66.187*/
/*s1240 130.76.4.122*/
/*cc08 172.16.23.54*/
/*zxj 10.20.41.253*/
/*t 10.20.0.239*/
if((socClient=OpenSocketStream("192.168.82.25",23,ErrorMessage))<0)
{
printf("Open Socket Error!!\n");
printf("ErrorMessage is %s \n",ErrorMessage);
return 0;
}
if(fcntl(socClient,F_SETFL,O_NONBLOCK) == -1)
{
printf("System error. O_NONBLOCK\n");
return -10;
}
strcpy(strBuff,"TERM=vt100\nexport TERM\nstty erase '^?'\n");
send(socClient, strBuff, strlen(strBuff), 0);
//send(socClient, "post\0", 4, 0);
for(;;)
{
j = 0;
for(;;)
{
nRtn=recv(socClient, szRecBuff,255, 0);
if(nRtn >0)
{
for(i=0;i<nRtn;i++)
{
if(szRecBuff[i]>32)
{
printf("%c ",szRecBuff[i]);
}
else
{
printf("%02x ",(unsigned char)szRecBuff[i]);
/*if(szRecBuff[i]==0)
szRecBuff[i]=0x20;*/
}
}
szRecBuff[nRtn] = '\0';
strcpy(szRecBuff,(char *)Negotiate(szRecBuff,socClient));
printf("\nrecv%d:%s\n",nRtn,szRecBuff);
j=0;
if(strstr(szRecBuff,"login:")||strstr(szRecBuff,"Password:")||strstr(szRecBuff,"#")||strstr(szRecBuff,"请输入口令"))
break;
if(strstr(szRecBuff,"login:")||strstr(szRecBuff,"Password:"))
{
if(!strstr(szRecBuff,"Last login:"))
break;
}
if(strstr(szRecBuff,"<"))
break;
}
else
{
j++;
if(j>10*10)
{
break;
}
usleep(1000*100);
}
printf("********* ceshi ********\n");
}
printf(":");
scanf("%s",strBuff);
printf("%s\n",strBuff);
for(i=0;i<strlen(strBuff);i++)
{
if(strBuff[i] == '~')
strBuff[i] = ' ';
}
if(strcmp(strBuff,"0") == 0)
{
sprintf(strBuff,"%s\0","post");
i = strlen(strBuff);
}
if(strcmp(strBuff,"1") == 0)
{
sprintf(strBuff,"%s\n","root");
i = strlen(strBuff);
}
if(strcmp(strBuff,"2") == 0)
{
sprintf(strBuff,"%s\n","root");
i = strlen(strBuff);
}
if(strcmp(strBuff,"3") == 0)
{
sprintf(strBuff,"%s\n","date");
i = strlen(strBuff);
}
nRtn=send(socClient, strBuff, i, 0);
if(nRtn == i)
{
printf("send cmd success %d\n",i);
}
else
{
printf("send cmd error\n");
}
}
close(socClient);
return 0;
}