⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialtestdlg.cpp

📁 GPRS拨号包括CMNET,CMWAP ,用程序实现WAP访问.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		strMsg.Format("Connection completed.\n");
		break;
	case   RASCS_Disconnected:   
		strMsg.Format("Disconnecting...\n");
		break;
	default:
		strMsg.Format("Unknown Status = %d\n", rasconnstate);
		break;
	}
//	AfxMessageBox(strMsg);

}   


void CDialTestDlg::OnButtonDialup() 
{
	// TODO: Add your control notification handler code here
	m_strRasLocalIp = "0.0.0.0";

	if (m_hRasConn)
	{
		RasHangUp(m_hRasConn);
		m_hRasConn = NULL;
	}

	RASDIALPARAMS params;
	memset(&params, 0, sizeof(params));
	params.dwSize = sizeof(params);
	strncpy(params.szEntryName, "2dddddddd2", sizeof(params.szEntryName));
	strncpy(params.szPhoneNumber, "*99***1#", sizeof(params.szPhoneNumber));
//	if (RasDial(NULL, NULL, &params, NULL, RasDialFunc, &m_hRasConn)!=0) 
	if (RasDial(NULL, NULL, &params, NULL, NULL, &m_hRasConn)!=0) 
	{
		if (m_hRasConn)
		{
			RasHangUp(m_hRasConn);
			m_hRasConn = NULL;
		}
		MessageBox("拨号失败");
		return;
	}

	DWORD size;
	RASPPPIP rpi;   
    ZeroMemory(&rpi, sizeof(rpi));   
    size = rpi.dwSize = sizeof(rpi); 
    if (RasGetProjectionInfo(m_hRasConn,   RASP_PppIp,   &rpi,   &size) != 0)
	{
		RasHangUp(m_hRasConn);
		m_hRasConn = NULL;
		MessageBox("拨号取本地IP失败");
		return;
	}

	m_strRasLocalIp = rpi.szIpAddress;

	SetDlgItemText(IDC_EDIT_RAS_LOCALIP, m_strRasLocalIp);


//	ShellExecute(m_hWnd, "route delete 0.0.0.0", NULL, NULL, NULL, SW_HIDE);
//	ShellExecute(m_hWnd, "route add 0.0.0.0 mask 0.0.0.0 192.168.7.250", NULL, NULL, NULL, SW_HIDE);
//	ShellExecute(m_hWnd, "route add 10.0.0.172 mask 255.255.255.255 " + m_strRasLocalIp, NULL, NULL, NULL, SW_HIDE);
//	ShellExecute(m_hWnd, "cmd", NULL, "route delete 0.0.0.0",  NULL, SW_SHOWNORMAL);
//	ShellExecute(m_hWnd, "cmd", NULL, "route add 0.0.0.0 mask 0.0.0.0 192.168.7.250",  NULL, SW_HIDE);
//	ShellExecute(m_hWnd, "cmd", NULL, "route add 10.0.0.172 mask 255.255.255.255 " + m_strRasLocalIp,  NULL, SW_HIDE);
	system("route delete 0.0.0.0");
	system("route add 0.0.0.0 mask 0.0.0.0 192.168.7.250");
	system("route add 10.0.0.172 mask 255.255.255.255 " + m_strRasLocalIp);


	OnButtonConnectTest();
}

void CDialTestDlg::OnButtonHangup() 
{
	// TODO: Add your control notification handler code here
	if (m_hRasConn)
	{
		RasHangUp(m_hRasConn);
		m_hRasConn = NULL;
	}
	
}

void CDialTestDlg::OnButtonClear() 
{
	// TODO: Add your control notification handler code here
	m_editReceive.SetWindowText("");
}

void CDialTestDlg::AddReceiveData(LPCTSTR lpszData, int nLen)
{
	CString strText;
	m_editReceive.GetWindowText(strText);
	int nFirstVisibleLine = m_editReceive.GetFirstVisibleLine();

	strText += lpszData;
	m_editReceive.SetWindowText(strText);
	m_editReceive.LineScroll(nFirstVisibleLine);
}

void CDialTestDlg::OnButtonConnectTest() 
{
	// TODO: Add your control notification handler code here
	CSocket sock;

	sock.Create(0, SOCK_STREAM);
	sock.Bind(0, m_strRasLocalIp);
	if (sock.Connect("10.0.0.172", 80) == 0)
	{
		MessageBox("连接 10.0.0.172:80 失败");
	}
	else
	{
		MessageBox("连接 10.0.0.172:80 成功");
	}

	sock.Close();

}

void CDialTestDlg::OnButtonGeturl() 
{
	// TODO: Add your control notification handler code here
	CString strContent = "GET http://wap.monternet.com/reversesubscribe?SessionID=&SPID=900616&ServiceID=03201587&SPURL=http://218.204.253.56/wap/sousuo/mfee.jsp?pid=68404&c=1 HTTP/1.1 \r\n\
host: wap.monternet.com \r\n\
Accept-Charset: utf-8;q=1.0,big5;q=0.5,euc-jp;q=0.5,euc-kr;q=0.5,gb2312;q=0.5,gbk;q=0.5,iso-10646-ucs-2;q=0.5,iso-2022-jp;q=0.5,iso-8859-1;q=0.5,iso-8859-15;q=0.5,iso-8859-2;q=0.5,iso-8859-3;q=0.5,iso-8859-7;q=0.5,iso-8859-9;q=0.5,korean;q=0.5,ks_c_5601;q=0.5,ks_c_5601-1987;q=0.5,shift_jis;q=0.5,us-ascii;q=0.5,utf-16;q=0.5,utf-16be;q=0.5,utf-16le;q=0.5,windows-1252;q=0.5,windows-1253;q=0.5,windows-1254;q=0.5,windows-1255;q=0.5,windows-1256;q=0.5,windows-1257;q=0.5,windows-1258;q=0.5,x-euc-jp;q=0.5,x-sjis;q=0.5 \r\n\
Accept-Language: en-GB; q=1.0, en; q=0.8 \r\n\
Accept-Encoding: deflate,gzip \r\n\
x-up-devcap-cc: 1 \r\n\
Accept: application/smil, application/vnd.oma.drm.content, application/vnd.oma.drm.message, application/vnd.oma.drm.rights+wbxml, application/vnd.oma.drm.rights+xml, application/vnd.phonecom.mmc-wbxml, application/vnd.phonecom.mmc-xml, application/vnd.wap.connectivity-wbxml, application/vnd.wap.mms-message, application/vnd.wap.multipart.mixed, application/vnd.wap.multipart.related, application/vnd.wap.wmlc;type=4365, application/vnd.wap.wmlscriptc, application/vnd.wap.xhtml+xml, application/xhtml+xml;profile=\"http://www.wapforum.org/xhtml\", image/bmp, image/gif, image/jpeg, image/png, image/vnd.wap.wbmp, multipart/mixed, multipart/related, text/html, text/plain, text/vnd.wap.connectivity-xml, text/vnd.wap.wml;type=4365, image/svg+xml, image/pjpeg, application/x-shockwave-flash, image/x-vnd.openwave.lzrw1, application/vnd.openwave.svg, text/vnd.sun.j2me.app-descriptor, application/java-archive, application/java, application/vnd.oma.dd+xml, image/ems, audio/wav, audio/x-wav, audio/midi, audio/x-midi \r\n\
User-Agent: Nokia6108/1.0 (03.20) Profile/MIDP-1.0 Configuration/CLDC-1.0 \r\n\
\r\n\
";

	m_nOrderStep = 0;
	m_strCookie = "";
	m_strLastURL = "";
	m_strReferURL = "";
	m_pSocket->ConnectAndSend(m_strRasLocalIp, "10.0.0.172", 80, strContent);

/*
	CString strContent = "GET http://upmobi.cn/ HTTP/1.1 \r\n\
Host: upmobi.cn \r\n\
Accept-Charset: utf-8;q=1.0,big5;q=0.5,euc-jp;q=0.5,euc-kr;q=0.5,gb2312;q=0.5,gbk;q=0.5,iso-10646-ucs-2;q=0.5,iso-2022-jp;q=0.5,iso-8859-1;q=0.5,iso-8859-15;q=0.5,iso-8859-2;q=0.5,iso-8859-3;q=0.5,iso-8859-7;q=0.5,iso-8859-9;q=0.5,korean;q=0.5,ks_c_5601;q=0.5,ks_c_5601-1987;q=0.5,shift_jis;q=0.5,us-ascii;q=0.5,utf-16;q=0.5,utf-16be;q=0.5,utf-16le;q=0.5,windows-1252;q=0.5,windows-1253;q=0.5,windows-1254;q=0.5,windows-1255;q=0.5,windows-1256;q=0.5,windows-1257;q=0.5,windows-1258;q=0.5,x-euc-jp;q=0.5,x-sjis;q=0.5 \r\n\
Accept-Language: en-GB; q=1.0, en; q=0.8 \r\n\
Accept-Encoding: deflate,gzip \r\n\
x-up-devcap-cc: 1 \r\n\
Accept: application/smil, application/vnd.oma.drm.content, application/vnd.oma.drm.message, application/vnd.oma.drm.rights+wbxml, application/vnd.oma.drm.rights+xml, application/vnd.phonecom.mmc-wbxml, application/vnd.phonecom.mmc-xml, application/vnd.wap.connectivity-wbxml, application/vnd.wap.mms-message, application/vnd.wap.multipart.mixed, application/vnd.wap.multipart.related, application/vnd.wap.wmlc;type=4365, application/vnd.wap.wmlscriptc, application/vnd.wap.xhtml+xml, application/xhtml+xml;profile=\"http://www.wapforum.org/xhtml\", image/bmp, image/gif, image/jpeg, image/png, image/vnd.wap.wbmp, multipart/mixed, multipart/related, text/html, text/plain, text/vnd.wap.connectivity-xml, text/vnd.wap.wml;type=4365, image/svg+xml, image/pjpeg, application/x-shockwave-flash, image/x-vnd.openwave.lzrw1, application/vnd.openwave.svg, text/vnd.sun.j2me.app-descriptor, application/java-archive, application/java, application/vnd.oma.dd+xml, image/ems, audio/wav, audio/x-wav, audio/midi, audio/x-midi \r\n\
User-Agent: Nokia6108/1.0 (03.20) Profile/MIDP-1.0 Configuration/CLDC-1.0 \r\n\
\r\n\
";

CString strContent = "GET http://upmobi.cn/ HTTP/1.1 \r\n\
Host: upmobi.cn \r\n\
Accept-Charset: utf-8;q=1.0,big5;q=0.5,euc-jp;q=0.5,euc-kr;q=0.5,gb2312;q=0.5,gbk;q=0.5,iso-10646-ucs-2;q=0.5,iso-2022-jp;q=0.5,iso-8859-1;q=0.5,iso-8859-15;q=0.5,iso-8859-2;q=0.5,iso-8859-3;q=0.5,iso-8859-7;q=0.5,iso-8859-9;q=0.5,korean;q=0.5,ks_c_5601;q=0.5,ks_c_5601-1987;q=0.5,shift_jis;q=0.5,us-ascii;q=0.5,utf-16;q=0.5,utf-16be;q=0.5,utf-16le;q=0.5,windows-1252;q=0.5,windows-1253;q=0.5,windows-1254;q=0.5,windows-1255;q=0.5,windows-1256;q=0.5,windows-1257;q=0.5,windows-1258;q=0.5,x-euc-jp;q=0.5,x-sjis;q=0.5 \r\n\
Accept-Language: en-GB; q=1.0, en; q=0.8 \r\n\
Accept-Encoding: deflate,gzip \r\n\
x-up-devcap-cc: 1 \r\n\
Accept: application/smil, application/vnd.oma.drm.content, application/vnd.oma.drm.message, application/vnd.oma.drm.rights+wbxml, application/vnd.oma.drm.rights+xml, application/vnd.phonecom.mmc-wbxml, application/vnd.phonecom.mmc-xml, application/vnd.wap.connectivity-wbxml, application/vnd.wap.mms-message, application/vnd.wap.multipart.mixed, application/vnd.wap.multipart.related, application/vnd.wap.wmlc;type=4365, application/vnd.wap.wmlscriptc, application/vnd.wap.xhtml+xml, application/xhtml+xml;profile=\"http://www.wapforum.org/xhtml\", image/bmp, image/gif, image/jpeg, image/png, image/vnd.wap.wbmp, multipart/mixed, multipart/related, text/html, text/plain, text/vnd.wap.connectivity-xml, text/vnd.wap.wml;type=4365, image/svg+xml, image/pjpeg, application/x-shockwave-flash, image/x-vnd.openwave.lzrw1, application/vnd.openwave.svg, text/vnd.sun.j2me.app-descriptor, application/java-archive, application/java, application/vnd.oma.dd+xml, image/ems, audio/wav, audio/x-wav, audio/midi, audio/x-midi \r\n\
User-Agent: Nokia6108/1.0 (03.20) Profile/MIDP-1.0 Configuration/CLDC-1.0 \r\n\
\r\n\
";


	m_pSocket->Send(strContent, strContent.GetLength());

#define MAX_RECEIVE_BUF 4096
	char szData[MAX_RECEIVE_BUF+1];
	int nRecv = 0;

	nRecv = m_pSocket->Receive(szData, MAX_RECEIVE_BUF);
	if (nRecv > 0 && nRecv <= MAX_RECEIVE_BUF)
	{
		szData[nRecv] = '\0';
		AddReceiveData(szData, nRecv);
	}
*/
}

void CDialTestDlg::DoParsePage(const CString &strPageContent)
{
	if (m_nOrderStep == 0)
	{
		StepForwardOrderURL(strPageContent);
	}
	else if (m_nOrderStep == 1)
	{
		StepOrderConfirm(strPageContent);
	}

}

void CDialTestDlg::StepForwardOrderURL(const CString &strPageContent)
{
	CString strURL;
	CString strHost;
	CString strTemp;

	CString strFindBegin = "<onevent type=\"onenterforward\">";
	CString strFindEnd = "</onevent>";
	
	int nPos1 = strPageContent.Find(strFindBegin);
	int nPos2 = 0;
	if (nPos1 >= 0)
	{
		nPos2 = strPageContent.Find(strFindEnd, nPos1+strFindBegin.GetLength());
		if (nPos2 >= 0)
		{
			strTemp = strPageContent.Mid(nPos1+strFindBegin.GetLength(), nPos2-nPos1-strFindBegin.GetLength()-1);
		}
	}
	nPos1 = strTemp.Find("href=\"");
	if (nPos1 >= 0)
	{
		nPos2 = strTemp.Find("\"", nPos1+6);
		if (nPos2 >= 0)
		{
			strURL = strTemp.Mid(nPos1+6, nPos2-nPos1-6);

		}
	}

	m_nOrderStep = 1;
	ParseHostFromURL(strURL, strHost);
	strURL.Replace("&amp;", "&");
	CString strSendData = PacketSendData("GET", strURL, strHost);
	m_strLastURL = strURL;
	m_strReferURL = "";
	m_pSocket->ConnectAndSend(m_strRasLocalIp, "10.0.0.172", 80, strSendData);



}

BOOL CDialTestDlg::ParseURL(const CString &strPageContent, CString &strOutURL, CString &strOutHost)
{
	strOutURL = "";
	strOutHost = "";

	int nPos1 = strPageContent.Find('\n');
	int nPos2 = 0;
	if (nPos1 > 0)
	{
		strOutURL = strPageContent.Left(nPos1);
		nPos1 = strOutURL.Find("GET ");
		if (nPos1 == 0)
		{
			strOutURL = strOutURL.Mid(4);
		}
		else
		{
			nPos1 = strOutURL.Find("POST ");
			if (nPos1 == 0)
			{
				strOutURL = strOutURL.Mid(5);
			}
		}

		nPos1 = strOutURL.Find(" HTTP/1.1");
		if (nPos1 > 0)
		{
			strOutURL.Left(nPos1);
		}
	}

	nPos1 = strOutURL.Find("://");
	if (nPos1 > 0)
	{
		nPos2 = strOutURL.Find("/", nPos1+3);
		if (nPos2 > 0)
		{
			strOutHost.Mid(nPos1+3, nPos2-nPos1-3);
		}
	}

	return TRUE;

}

void CDialTestDlg::ParseHostFromURL(const CString &strURL, CString &strHost)
{
	int nPos1 = strURL.Find("://");
	int nPos2 = 0;

	if (nPos1 > 0)
	{
		nPos2 = strURL.Find("/", nPos1+3);
		if (nPos2 > 0)
		{
			strHost = strURL.Mid(nPos1+3, nPos2-nPos1-3);
		}
	}

	strHost.TrimRight();
}

CString CDialTestDlg::PacketSendData(LPCTSTR lpszMethod, LPCTSTR lpszURL, LPCTSTR lpszHost, LPCTSTR lpszCookie, LPCTSTR lpszPostData)
{
	CString strData;
	CString strFormat = "%s %s HTTP/1.1 \r\n\
host: %s \r\n\
Accept-Charset: utf-8;q=1.0,big5;q=0.5,euc-jp;q=0.5,euc-kr;q=0.5,gb2312;q=0.5,gbk;q=0.5,iso-10646-ucs-2;q=0.5,iso-2022-jp;q=0.5,iso-8859-1;q=0.5,iso-8859-15;q=0.5,iso-8859-2;q=0.5,iso-8859-3;q=0.5,iso-8859-7;q=0.5,iso-8859-9;q=0.5,korean;q=0.5,ks_c_5601;q=0.5,ks_c_5601-1987;q=0.5,shift_jis;q=0.5,us-ascii;q=0.5,utf-16;q=0.5,utf-16be;q=0.5,utf-16le;q=0.5,windows-1252;q=0.5,windows-1253;q=0.5,windows-1254;q=0.5,windows-1255;q=0.5,windows-1256;q=0.5,windows-1257;q=0.5,windows-1258;q=0.5,x-euc-jp;q=0.5,x-sjis;q=0.5 \r\n\
Accept-Language: en-GB; q=1.0, en; q=0.8 \r\n\
Accept-Encoding: deflate,gzip \r\n\
x-up-devcap-cc: 1 \r\n\
Accept: application/smil, application/vnd.oma.drm.content, application/vnd.oma.drm.message, application/vnd.oma.drm.rights+wbxml, application/vnd.oma.drm.rights+xml, application/vnd.phonecom.mmc-wbxml, application/vnd.phonecom.mmc-xml, application/vnd.wap.connectivity-wbxml, application/vnd.wap.mms-message, application/vnd.wap.multipart.mixed, application/vnd.wap.multipart.related, application/vnd.wap.wmlc;type=4365, application/vnd.wap.wmlscriptc, application/vnd.wap.xhtml+xml, application/xhtml+xml;profile=\"http://www.wapforum.org/xhtml\", image/bmp, image/gif, image/jpeg, image/png, image/vnd.wap.wbmp, multipart/mixed, multipart/related, text/html, text/plain, text/vnd.wap.connectivity-xml, text/vnd.wap.wml;type=4365, image/svg+xml, image/pjpeg, application/x-shockwave-flash, image/x-vnd.openwave.lzrw1, application/vnd.openwave.svg, text/vnd.sun.j2me.app-descriptor, application/java-archive, application/java, application/vnd.oma.dd+xml, image/ems, audio/wav, audio/x-wav, audio/midi, audio/x-midi \r\n\
User-Agent: Nokia6108/1.0 (03.20) Profile/MIDP-1.0 Configuration/CLDC-1.0 \r\n\
%s%s%s%s\
\r\n\
%s\
";
	CString strContentType = "";
	CString strCookie = "";
	CString strContentLength = "";
	CString strReferer = "";
	CString strPostData = lpszPostData;
	if (lpszCookie && strlen(lpszCookie) > 0)
	{
		strCookie.Format("Cookie: %s\r\n", lpszCookie);
	}
	if (lpszPostData && strlen(lpszPostData) > 0)
	{
		strContentLength.Format("Content-Length: %d\r\n", strlen(lpszPostData));
	}
	if (!m_strReferURL.IsEmpty())
	{
		 strReferer.Format("Referer: %s\r\n", m_strReferURL);
	}

	if (lpszMethod && stricmp(lpszMethod, "POST") == 0)
	{
		strContentType = "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
	}

	strData.Format(strFormat, lpszMethod, lpszURL, lpszHost, strContentType, strCookie, strReferer, strContentLength, strPostData);

	return strData;
}

void CDialTestDlg::StepOrderConfirm(const CString &strPageContent)
{
	CString strHeadData;
	CString strPageData;

	int nPos1 = strPageContent.Find("\r\n\r\n");
	int nPos2 = strPageContent.Find("\n\n");
	int nPos = 0;

	if (nPos1 > 0  && nPos2 > 0)
	{
		nPos = nPos1 > nPos2 ? nPos2 : nPos1;
	}
	else if (nPos1 > 0)
	{
		nPos = nPos1;
	}
	else if (nPos2 > 0)
	{
		nPos = nPos2;
	}

	strHeadData = strPageContent.Left(nPos);
	strPageData = strPageContent.Mid(nPos);

	nPos1 = strHeadData.Find("\nSet-Cookie:");
	if (nPos1 > 0)
	{
		nPos2 = strHeadData.Find("\n", nPos1+1);
		if (nPos2 > 0)
		{
			m_strCookie = strHeadData.Mid(nPos1+12, nPos2-nPos1-12);
			m_strCookie.TrimLeft(" \r\n");
			m_strCookie.TrimRight(" \r\n");
			nPos1 = m_strCookie.Find("xid=");
			if (nPos1 > 0)
			{
				nPos2 = m_strCookie.Find(";", nPos1);
				if (nPos2 > 0)
				{
					m_strCookie = m_strCookie.Mid(nPos1, nPos2-nPos1);
				}
				else
				{
					m_strCookie = m_strCookie.Mid(nPos1);
				}
			}
		}
	}

	CString strAnchor = "";
	CString strPostItemName = "";
	CString strPostItemValue = "";
	CString strPostField = "";
	CString strGo = "";
	CString strHref = "";
	CString strSendRefer = "";
	CString strHost = "";
	CString strPostData = "";


	nPos1 = strPageData.Find("<anchor>");
	if (nPos1 > 0)
	{
		nPos2 = strPageData.Find("</anchor>", nPos1 +1);
		if (nPos2 > 0)
		{
			strAnchor = strPageData.Mid(nPos1+8, nPos2-nPos1-8);
			if (strAnchor.Find("鎴戣

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -