- 论坛徽章:
- 0
|
本帖最后由 bress111 于 2012-07-19 09:34 编辑
UpdateData(TRUE);
CString str = m_Connect_UserName.GetBuffer(0);
DWORD dwTarget_IP;
CString csTemp;
m_Target_IP.GetAddress(dwTarget_IP);
csTemp = IPToStr(dwTarget_IP);
LIBSSH2_SESSION *session;
int rc;
const char *fingerprint;
int auth_pw = 0;
char *userauthlist;
WSADATA wsadata;
WSAStartup(MAKEWORD(2,0), &wsadata);//启动win32下的socket服务,经验证,启动正常
socket_handle = socket(AF_INET, SOCK_STREAM, 0);//创建一个socket句柄,创建成功if (socket_handle <= 0)
{
MessageBox(_T("Socket创建失败" );
}
sprintf_s(Target_Connect_IP, "%S", csTemp);
struct sockaddr_in addr;
addr.sin_family=AF_INET;
addr.sin_port=htons(mTarget_Port);
addr.sin_addr.s_addr=inet_addr(Target_Connect_IP);
memset(&(addr.sin_zero),0, ;
int result=connect(socket_handle,(struct sockaddr *)&addr,sizeof(addr));//创建一个connect连接,成功
if (result < 0)
{
DWORD Connect_Error=GetLastError();
CString str1;
str1.Format(_T("%u" ,Connect_Error);
MessageBox(str1,_T("连接失败" ,MB_OK);
}
if(!(session = libssh2_session_init()))//创建会话,成功{
MessageBox(_T("会话创建失败" ,_T("创建会话" ,MB_OK);
}
if((rc = libssh2_session_startup(session, socket_handle)))//创建ssh2会话,成功{
MessageBox(_T("SSH会话创建失败" ,_T("创建SSH会话" ,MB_OK);
libssh2_session_free(session);
}
fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
userauthlist = libssh2_userauth_list(session, username, strlen(username));
int ValidationErr1=libssh2_userauth_password(session, "root", "123" ;//验证用户名和密码,问题出现了,用户名和密码绝对正确,端口22也没有错,但是验证失败,不知道为什么。
CString str41;
str41.Format(_T("%d" ,ValidationErr1);
MessageBox(str41);//此处打印出来的结果为-18,查了一下对应的错误码为LIBSSH2_ERROR_AUTHENTICATION_FAILED,也就是用户名和密码错误或无效,用户名和密码绝对的绝对没有错。
用工具SecureCRT用同样的IP、用户名、密码并选择ssh2方式,是可以登录成功的,跪求哪位高手给小弟看看,感激不尽啊! |
|