1
이 프로그램은 호스트 이름과 사용자 이름을 사용하고 SSH를 통해 손가락을 사용하여 연결하며 이전에는 작동했지만이 프로그램을 실행하면 사용자 이름이 무시되고 이름이 사용됩니다 그게 내 껍질에 나타나서 올바른 결과를 얻지 못해.프로그램이 사용자 입력 대신 터미널 이름을 사용합니다.
쉘은 Matt $로 시작하고이 프로그램은 userName @ server 대신 Matt @ server를 실행합니다.
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <stdio.h>
#include <ctype.h>
int main()
{
std::string CommandString;
char buffer1 [274];
printf("Enter your Host Name; it must be characters and not more than 255");
char hostName[254];
int len2;
fgets(hostName, sizeof(hostName), stdin);
rewind (stdin);
len2 = strlen(hostName);
if(hostName[len2-1] == '\n') hostName[--len2] = '\0';
if(len2 >254 ||!isalpha(hostName[len2-1]))
{
printf("Invalid Host Name");
}
printf("Enter your User Name; it must be characters and not more than 20");
char userName[19];
int len;
fgets(userName, sizeof(userName), stdin);
rewind (stdin);
len = strlen(userName);
if(userName[len-1] == '\n') userName[--len] = '\0';
if(len >19 || isalpha(userName[19]))
{
printf("Invalid User Name");
}
sprintf(buffer1,"ssh %s usr/bin/finger %s",hostName,userName);
system((char*)buffer1);
return 0;
}
많은 것들이, 이것은'c'와'C++ '몇 가지 것들을 가지고 있기 때문에'gcc'를 던져서 컴파일하지 않을 것입니다. 맨 위에있는'std :: string'과'#includes '. 두 fgets() 호출은 버퍼의 전체 크기를 읽고'buf [sizeof buf - 1] = '\ 0을 절대로 설정하지 않기 때문에 끝에'\ 0'이없는 문자열을 가질 위험이있다. '''strlen()'을하기 전에. 마지막으로, 원격 컴퓨터에서'finger '를 호출하려고합니까? 앞에'/'가 필요하고' @ '이 올바르게 구성되어야합니다. –
Macattack
예 원격 시스템에서 finger에 전화하려고합니다. 알았어, 네 제안대로 정리 해줄거야. –