通过特定获取获取电脑外网IP地址

void  get_WanIp()
{
    
    char Buf_File_Read[MAX_PATH] = {0};  
    char IP_Temp[128];  
    char IP_Host[64];  
    int Result_URLDownloadToFile = 1;  
    char szFilePath[MAX_PATH] = {0};
    GetTempPathA(MAX_PATH,szFilePath);
    strcat(szFilePath,"IPinTheWorld.ini");

      
    Result_URLDownloadToFile = URLDownloadToFileA(0,"http://ip.dnsexit.com/index.php",szFilePath,0,NULL);  
    if(Result_URLDownloadToFile != 0)//若URLDownloadToFile()成功,返回0  
    {  
        MessageBox(NULL, "网络故障,无法接入Internet,请联系网络管理员","提示",MB_ICONASTERISK);  
        return ;  
    }  
      
    FILE *fp_Download_URL_File=NULL;  
    if ((fp_Download_URL_File=fopen( szFilePath,"r")) == NULL)  
    {  
        MessageBox(NULL, "系统故障,无法打开IP文件,请检查防火墙设置或联系管理人员","提示",MB_ICONASTERISK);  
        return ;  
    }  
  
    if ( fp_Download_URL_File != NULL )  
    {  
        fseek(fp_Download_URL_File, 0, SEEK_SET);  
        fread(Buf_File_Read,1,256,fp_Download_URL_File);  
        fclose(fp_Download_URL_File);
        DeleteFile(szFilePath); 
    }
    strcpy(g_szWanIp,Buf_File_Read);
}

 

posted @ 2013-06-26 13:12  瓜蛋  阅读(663)  评论(0编辑  收藏  举报