t.c
上传用户:chaoqun
上传日期:2013-06-29
资源大小:1k
文件大小:3k
- #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_NONBLOCKn");
- return -10;
- }
-
- strcpy(strBuff,"TERM=vt100nexport TERMnstty erase '^?'n");
- send(socClient, strBuff, strlen(strBuff), 0);
- //send(socClient, "post ", 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] = ' ';
- strcpy(szRecBuff,(char *)Negotiate(szRecBuff,socClient));
- printf("nrecv%d:%sn",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("%sn",strBuff);
- for(i=0;i<strlen(strBuff);i++)
- {
- if(strBuff[i] == '~')
- strBuff[i] = ' ';
- }
- if(strcmp(strBuff,"0") == 0)
- {
- sprintf(strBuff,"%s ","post");
- i = strlen(strBuff);
- }
-
- if(strcmp(strBuff,"1") == 0)
- {
- sprintf(strBuff,"%sn","root");
- i = strlen(strBuff);
- }
- if(strcmp(strBuff,"2") == 0)
- {
- sprintf(strBuff,"%sn","root");
- i = strlen(strBuff);
- }
- if(strcmp(strBuff,"3") == 0)
- {
- sprintf(strBuff,"%sn","date");
- i = strlen(strBuff);
- }
-
- nRtn=send(socClient, strBuff, i, 0);
- if(nRtn == i)
- {
- printf("send cmd success %dn",i);
- }
- else
- {
- printf("send cmd errorn");
- }
-
-
-
- }
-
- close(socClient);
- return 0;
-
- }