#include <afxinet.h>//gb2312 converted to unicodewchar_t* gb2312tounicode (const char* szgbstring) {UINT ncodepage = 936; /gb2312 int Nlength=multibytetowidechar (ncodepage,0,szgbstring,-1,null,0); wchar_t* pbuffer = new Wchar_t[nlength+1]; MultiByteToWideChar (ncodepage,0,szgbstring,-1,pbuffer,nlength); pbuffer[nlength]=0; return pbuffer;} CString Cnetdlg::getnetip () { cstring internetip = _t (""); char chSource[4096] = {0} ; cstring straddress; cinternetsession mysession (NULL,0); chttpfile* myhttpfile=null; straddress = _t ("http://20140507.ip138.com/ic.asp");//ip138 Web page TRY { myhttpfile = (chttpfile*) mysession.openurl (straddress);//Read network address while (Myhttpfile->read (Chsource, 4096)) {   //Loop read downloaded page text int begin = 0; & nbsp //now only deal with the case of character set gb2312 begin = CKMP <byte*>::find (byte*) Chsource, strlen (Chsource), (byte*) _c ("charset=gb2312"),; if (begin! =-1) & nbsp; { wchar* Wchsource = Gb2312tounicode (chsource); internetip = wchsource; Delete[] wchsource; } begin = Internetip.find (_t ("["), 0); if (begin!=-1)//If you find "[", find "]" the text inside the brackets is your extranet ip & nbsp; { int End=internetip.find (_t ("]")); Internetip = Internetip.mid (begin+1, end-begin-1);//extract extranet ip break; } } myhttpfile->close (); Mysession.close (); } catch (cinternetexception,e) { internetip.format (t_t (_$_string_format_1), E->m_dwerror, E->m_dwcontext); } catch_all (e) { tchar Ch[max_path] = {0}; e->geterrormessage (CH, MAX_PATH); internetip.format (t_t (_$_string_format_1), -3, ch); } END_CATCH_ALL trace (internetip); return Internetip;}
References:
http://blog.csdn.net/cbk861110/article/details/7844729
Web address
Http://20140507.ip138.com/ic.asp
From
Http://www.ip138.com
Found in the Web page source code.
<TR><TD align= "center" >
MFC C + + gets extranet IP address