今天看啥
热点:

vc获取本地IP和机器名,vc获取ip


#include 
#include 
#include 
#pragma comment(lib,"ws2_32.lib")
std::string GetLocalIpAndSave(void) 
{
	WSADATA wsaData;
	char name[155];
	std::string strIp;
	PHOSTENT hostinfo; 
	if ( WSAStartup( MAKEWORD(2,0), &wsaData ) == 0 ) {  
		if( gethostname ( name, sizeof(name)) == 0) {     //获取机器名
			if((hostinfo = gethostbyname(name)) != NULL) { //这些就是获得IP的函数
				strIp = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list); //获取本机ip
			} 
		} 
		WSACleanup( );
	}
	CHAR path[MAX_PATH] = {0};
	GetModuleFileNameA(NULL, path, MAX_PATH);
	boost::filesystem::path fpath(path);
	fpath = fpath.parent_path();
	fpath /= "serverip.txt";
	FILE* f = fopen(fpath.string().c_str(), "wb+");
	fwrite(PVOID(strIp.c_str()), strIp.size(), 1, f);
	fclose(f);
	return strIp;//返回本机ip
}

www.513bk.comtruehttp://www.513bk.com/VCjc/1237380.htmlTechArticlevc获取本地IP和机器名,vc获取ip #include #include #include #pragma comment(lib,ws2_32.lib)std::string GetLocalIpAndSave(void) {WSADATA wsaData;char name[155];std::string...

相关文章

相关搜索: 机器

帮客评论

视觉看点