用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c++代码库

VPN连接

2014-10-08 作者: someoneac举报

[c++]代码库

CRas        ras;
	RASENTRY	rasEntry;
	char        strName[50];// = "COMKK";

	DWORD			lpcb	=	0;
	DWORD			lpcDevices;	
	RASDEVINFO*		lpRasDevInfo;
	RASDEVINFO		rasdevinfo; 
	
	strcpy(strName,VPNName.GetBuffer(VPNName.GetLength()));
	RasEnumDevices(NULL, &lpcb, &lpcDevices);
	lpRasDevInfo = (LPRASDEVINFO) GlobalAlloc(GPTR, lpcb);
	lpRasDevInfo->dwSize = sizeof(RASDEVINFO);
	RasEnumDevices(lpRasDevInfo, &lpcb, &lpcDevices);
	strcpy (rasdevinfo.szDeviceName, lpRasDevInfo->szDeviceName);
	strcpy (rasdevinfo.szDeviceType, lpRasDevInfo->szDeviceType);

	rasEntry.dwSize				= sizeof (RASENTRY);
	//rasEntry.dwfOptions		= RASEO_RemoteDefaultGateway | RASEO_SpecificNameServers;
	//rasEntry.dwfOptions       = RASEO_RequireMsEncryptedPw | RASEO_RequireDataEncryption;
	rasEntry.dwAlternateOffset	= 0;
	rasEntry.dwCountryID		= 86;
	rasEntry.dwCountryCode		= 86;
//	rasEntry.dwDialExtraPercent = 75;
//	rasEntry.dwDialExtraSampleSeconds = 120;
//	rasEntry.dwDialMode         = 1;
//	rasEntry.dwVpnStrategy = 1;
//	rasEntry.dwfNetProtocols = 4;
	rasEntry.dwfOptions = 1024262928;
//	rasEntry.dwfOptions2 = 367;
	rasEntry.dwFramingProtocol = 1;
//	rasEntry.dwHangUpExtraPercent = 10;
//	rasEntry.dwHangUpExtraSampleSeconds = 120;
//	rasEntry.dwRedialCount = 3;
//	rasEntry.dwRedialPause = 60;
//	rasEntry.dwType = RASET_VPN;

	rasEntry.dwFrameSize		= 0;
	rasEntry.dwfNetProtocols	= RASNP_Ip;		// TCP/IP
	rasEntry.dwFramingProtocol	= RASFP_Ppp;	//PPP
	rasEntry.dwChannels			= 0;
	rasEntry.dwReserved1		= 0;
	rasEntry.dwReserved2		= 0;	

	// Strings
	strcpy (rasEntry.szAreaCode, " ");
	strcpy (rasEntry.szScript, "");
	strcpy (rasEntry.szAutodialDll, "");
	strcpy (rasEntry.szAutodialFunc, "");
	strcpy (rasEntry.szX25PadType, "");
	strcpy (rasEntry.szX25Address, "");
	strcpy (rasEntry.szX25Facilities, "");
	strcpy (rasEntry.szX25UserData, "");
	strcpy (rasEntry.szDeviceName,"WAN 微型端口 (PPTP)");
	strcpy (rasEntry.szDeviceType, "vpn");	
	strcpy (rasEntry.szLocalPhoneNumber, VPNAddress.GetBuffer(VPNAddress.GetLength()));/*"140.207.3.74"59.188.23.84"218.242.176.71"*///服务器地址或域名

//	rasEntry.dwVpnStrategy = VS_DEFAULT;     //vpn类型
//	rasEntry.dwEncryptionType = ET_OPTIONAL; //数据加密类型    

	// IP addresses
	InitRASIP (rasEntry.ipaddr);
	InitRASIP (rasEntry.ipaddrDns);
	InitRASIP (rasEntry.ipaddrDnsAlt);
	InitRASIP (rasEntry.ipaddrWins);
	InitRASIP (rasEntry.ipaddrWinsAlt);

	//Create Entry
    DWORD			dwError;
	
	dwError = ras.RasSetEntryProperties (NULL, strName, &rasEntry, sizeof (RASENTRY), NULL, NULL);
	if (dwError == 0) {
		RASDIALPARAMS	dialParm;
		dialParm.dwSize = sizeof (RASDIALPARAMS);

		strcpy (dialParm.szEntryName, strName);
		strcpy (dialParm.szPhoneNumber, "");
		strcpy (dialParm.szCallbackNumber, "");
		strcpy (dialParm.szUserName,VPNUser.GetBuffer(VPNUser.GetLength()));// "zdx"/*"hdj"*/
		strcpy (dialParm.szPassword,VPNPass.GetBuffer(VPNPass.GetLength()));// "19881011"/*"hdj"*/
		strcpy (dialParm.szDomain, "");
		dwError = ras.RasSetEntryDialParams(NULL, &dialParm,FALSE);
		if( dwError == 0 ) {
			//dwError = ras.RasSetCredentials(NULL, strName, &rasEntry, 0);
			m_log += "正在进行网络连接,请稍候...\r\n";
			frameWnd->PostMessage(WM_UPDATE_MESSAGE,0,0);
			//SetDlgItemText( IDC_EDIT_LOG, "正在进行网络连接,请稍候..." );

			dwError = RasDial( NULL, NULL, &dialParm, 0L, NULL, &m_hRasConn );
			if ( dwError ) {
				char  szBuf[256] = "";

				// 网络连接错误
				if ( RasGetErrorString( (UINT)dwError, (LPSTR)szBuf, 255 ) != 0 ) {
					_stprintf( (LPTSTR)szBuf, "Undefined RAS Dial Error (%ld).", dwError );
					
				}
				
				m_log += "网络连接异常...";
				frameWnd->PostMessage(WM_UPDATE_MESSAGE,0,0);
				//SetDlgItemText( IDC_EDIT_LOG, szBuf ),
					EndDialog(FALSE);
				//return FALSE;
			}
		}
	}
	
	m_log += "远程网络已正常连接!\r\n";
	frameWnd->PostMessage(WM_UPDATE_MESSAGE,0,0);


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...