获取外网IP的方法

 void GetIP() 
{ 
   CInternetSession session; 
   const CString strUrl = TEXT("http://iframe.ip138.com/ip2city.asp");
   CInternetFile * httpfile = (CInternetFile *)session.OpenURL(strUrl); 
   CString strContent = TEXT("");   
   CString strData = TEXT("");
   while(httpfile->ReadString(strContent)) 
   { 
        strData += strContent;
   } 
   int nStart = strData.Find("[");
   int nEnd   = strData.Find("]"); 
   int nCount = nEnd - nStart;
   strData    = strData.Mid(nStart + 1,nCount - 1);

   MessageBox("您的ip是: "+strData);

   httpfile->Close();   
   session.Close(); 
}

你可能感兴趣的:(开发笔记,C,外网ip)