const int WILL = 251;
const int WONT = 252;
const int DO = 253;
const int DONT = 254;
const int IAC = 255;
const int RD = 1;
const int SGA = 3;
class CTelnetDLLApp : public CWinApp
{
public:
CSocket Client;
const CString LoginPrompt = ":";
CString prompt;
public:
CTelnetDLLApp();
BOOL Connect(char *hostname, int port, char *username, char *password, int waitTime = 300);
CString Send(CString cmd, int waitTime = 500);
VOID Close();
CString ReadUntil(CString pattern);
CString Negotiate();
CString RemoveNoString(CString);
// 重写
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
/**********************************************************************************************/
BOOL CTelnetDLLApp::Connect(char *hostname, int port,char *username,char *password,int waitTime)
{
AfxSocketInit();
if (!Client.Create())
{
return FALSE;
}
if (Client.Connect((LPCTSTR)hostname, port))
{
Negotiate();
CString u(username);
CString p(password);
CString result;
u += "\r\n";
p += "\r\n";
prompt = (u == "root\r\n" ? &