文件名称:ip地址的获取
文件大小:43KB
文件格式:DOC
更新时间:2015-12-19 16:54:40
ip
*****//*函数说明:获取当前外网IP地址/*参数:无/*返回值:返回外网IP地址、CString类型字符串/*By:Koma2009.08.2114:12//用3322获取外网IP最为方便,直接读取网页源码,不用查找,网页源码就是外网IP/************************************************************************/CStringGetIP(CStringsite)//读取网页源码的函数{CInternetSessionmySession(NULL,0);CHttpFile*myHttpFile=NULL;CStringm_SiteInfo;CStringmyData;myHttpFile=(CHttpFile*)mySession.OpenURL(site);//http://www.3322.org/dyndns/getipwhile(myHttpFile->ReadString(myData)){m_SiteInfo+=myData;}myHttpFile->Close;mySession.Close;returnm_SiteInfo;}/************************************************************************//*函数说明:获取当前主机名/*参数:无/*返回值:返回主机名、CString类型字符串/*By:Koma2009.08.2114:23/************************************************************************/CStringCQDlg::GetHostName(){WORDwVersionRequested;WSADATAwsaData;interr;wVersionRequested=MAKEWORD(2,0);err=WSAStartup(wVersionRequested,&wsaData;);if(err!=0){return err; }if(LOBYTE(wsaData.wVersion!=2)||HIBYTE(wsaData.wVersion)!=0){WSACleanup();return(char)WSAVERNOTSUPPORTED;}charszHostName[256];intnRetCode;CStringstr=”";//调用API来获得主机名nRetCode=gethostname(szHostName,sizeof(szHostName));if(nRetCode!=0){returnWSAGetLastError();}if(szHostName!=“”){str.Format(“主机名:%s”,szHostName);}returnstr;}