It should be added to the project check the validity of proxy servers. The algorithm works is simple:
1. I’m trying to connect to a specific server via a proxy.
2. I get the page contents (the address).
3. Connecting to the same server directly.
4. Compare their addresses if they match the proxy is not anonymous.
But for some reason after the program to connect to the proxy first, thenattempt to get a connection through another proxy or directly is not successful. When I read the address you always get the address of the first proxy.
After some time trying to run the test, checking all begins to work properly.but enough to restart Windows and start all over again.
What am I doing wrong?
Project http://dl.dropbox.com/u/10669949/work/internet_site.zip
CString CDataSender::GetNotDirect(CString proxy)
{
try
{
auto_ptr<CString> proxyip(new CString);
CString page ="/ip.php";
CString host="176.65.165.57";
if (proxy.IsEmpty()) return "";
auto_ptr<CInternetSession> iProxy (new CInternetSession("Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.8.131 Version/11.11",1,INTERNET_OPEN_TYPE_PROXY,proxy));
auto_ptr<CHttpConnection> pH(iProxy->GetHttpConnection(host,INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_PRAGMA_NOCACHE,80));
auto_ptr<CHttpFile> pF(pH->OpenRequest("GET",page));
pF->SendRequest();
pF->ReadString(*proxyip);
iProxy->Close();
pH->Close();
pF->Close();
return *proxyip;
}
catch(CInternetException *pEx)
{
cout<<pEx->m_dwError<<endl;
return "";
}
}
CString CDataSender::GetDirect()
{
try
{
auto_ptr<CString> directip(new CString);
int nCount=0;
CString page ="/ip.php";
CString host="176.65.165.57";
auto_ptr<CInternetSession> iDirect(new CInternetSession (/*"Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.8.131 Version/11.11"*/"",1,INTERNET_OPEN_TYPE_DIRECT));
auto_ptr<CHttpConnection> pH(iDirect->GetHttpConnection(host,INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_PRAGMA_NOCACHE,80));
auto_ptr<CHttpFile> pF(pH->OpenRequest("GET",page));
pF->SendRequest();
pF->ReadString(*directip);
iDirect->Close();
//////////////////////////////////////////////////////////////////////////
pH->Close();
pF->Close();
return *directip;
}
catch(CInternetException *pEx)
{
cout<<pEx->m_dwError<<endl;
return "";
}
}
int CDataSender::CheckProxy(CString proxy)
{
CString directip="",proxyip="";
proxyip.Empty();directip.Empty();
proxyip=GetNotDirect(proxy);
if(proxyip!="")
directip=GetDirect();
else
return -1;
cout<<"Direct: "<<directip<<endl;
cout<<"Proxy: "<<proxyip<<endl;
if ((proxyip!="")&&(directip!="")&&(proxyip.Find("html")==-1)&&/*(proxyip.GetLength()<16) &&*/(proxyip.Find(directip)==-1) /*|| proxyip=="1.1.1.1"*/)
{
return 1;
}
return -1;
}
Solved the problem. Added the appropriate flags.
Similarly, for another function.