越简单越好阿
要以***.***.***.***格式保存的
要以***.***.***.***格式保存的
解决方案 »
- 【【【【【VC视频】】】】】】
- 10万个用户同时在线,登录到不同的服务器,如何做到IOCP服务器之间的数据交换和负载平衡呢?
- 请问如何获得combobox(droplist) 中某字符串的位置值?谢谢
- 请问在系统中socket handle是不是象窗口句柄HWND一样,是唯一的
- 我自己的类如何在MFC的框架中起作用?是不是不能用文档视图结构来实现?
- 请求用openh323编程问题!
- 数据库抛出异常,在release下和debug下表现不同
- 帮帮忙,谢谢~~~~~~~~~~~~~~~~`
- 使用CHtmlView编程,如何获取鼠标点中超链接的路径名
- Dialog的SetFont为啥无效呢?
- 请问如何一次性删除表中的所有记录?
- 急,如何从一个unsigned char数组中取最后4个字节组成DWORD的值
{
struct in_addr localaddr;
struct hostent *hp=NULL;
char hostname[50];
gethostname(hostname,49);//主机名
hp=gethostbyname(hostname);主机信息
memcpy(&localaddr,hp->h_addr,hp->length);//地址
return inet_ntoa(localaddr);//变成char *}
完全同意SeainBlue(爱海)的办法
楼上的几位方法也都很好
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}WSACleanup( );
}
AfxMessageBox(name);//name里是本机名
AfxMessageBox(ip); //ip中是本机IP
}
#include <windows.h>char* GetLocalIP(void)
{
WSADATA wsadata;
char szHostName[MAX_PATH + 1] = "\0";
hostent *phe;
in_addr myip; if (WSAStartup(MAKEWORD(2,2), &wsadata) != 0)
{
return NULL;
}
if(gethostname(szHostName, MAX_PATH ) == 0)
{
phe = gethostbyname(szHostName);
memcpy((char*)&myip, phe->h_addr_list[0], 4);
WSACleanup();
return (inet_ntoa(myip));
}
else
{
WSACleanup();
return NULL;
}
}
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString strIP;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
strIP = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
} char* pszLocalIPAddr;
pszLocalIPAddr=new char[strIP.GetLength()+1];
strcpy(pszLocalIPAddr,(LPCSTR)strIP);
return pszLocalIPAddr;
}