轻轻松松..获得自己的公网IP..

2008-12-12

CString CWinDlg::getMyIp()

{

CString str=””;

CString myWeb; //源码

CString everWeb; //整理后的源码

CInternetSession localsession;   //定义网络连接

CInternetFile *webfile=NULL;     //定义一个文件对象指针

try

{

   webfile=(CInternetFile*) localsession.OpenURL(str);

}

catch (CInternetException *pException)

{

   webfile=NULL;

   pException->Delete();

}

if (webfile)

{

   while (webfile->ReadString(myWeb))

   {

    everWeb+=myWeb;

   }

}

//下面是将获得的源码进行分解.. 获得IP…

int ipTemp=everWeb.Find(“IPMessage”)+11;

CString ip=””;

//获得IP…

do

{

   ip+=everWeb.GetAt(ipTemp++);

} while (everWeb.GetAt(ipTemp)!=’