//查找网页源码,这段代码也可以作为获取外网IP,不过获取外网IP只需要前面一部分就行了,把网页源码读到缓冲区就行了 

CString SiteInfo,SiteName=”http://www.ip138.com/ip2city.asp“;
 CInternetSession mySession(NULL,0);
 CHttpFile *myHttpFile=NULL;
 CString myData;
 myHttpFile=(CHttpFile *)mySession.OpenURL(SiteName);
 while(myHttpFile->ReadString(myData))
 {
  SiteInfo=SiteInfo+”\r\n”;
  SiteInfo+=myData;
 }

 myHttpFile->Close();
 mySession.Close();//前面是获取网页源代码

/* CFile file;
 file.Open(“file.tmp”,CFile::modeRead);
 CString data;
 while(file.ReadHuge(data.GetBuffer(1024),1024))
 {
     CString yourIP(“您的IP地址是:”);
  CString end(“<br/><br/></td>”);
  int index=data.Find(yourIP);
  if(index!=-1)
  {
   int length=data.Find(end)-index;
   GetDlgItem(IDC_EDIT1)->SetWindowText(data.Mid(index,length));
   GetDlgItem(IDC_EDIT2)->SetWindowText(“获取完毕”);
   break;
  }
  data.ReleaseBuffer(1024);
 }
 file.Close();//前面是在网页代码中查找IP
*/
posted on 2011-05-24 20:06  °ι 、曲 终  阅读(779)  评论(0编辑  收藏  举报