可否通过Windows局域网中的主机名获得主机的IP地址,怎样操作???期待你的高见,高分奉送。
解决方案 »
- 找工作,专长是C++,北京地区,不计较工资,需要的联系我
- 请问如何获取IP地址改变的消息
- 寻求类中使用vector发生错误的解决办法?
- 为什么会有do{...}while(0);的写法?
- 如何打开一个路径选择对话框?
- 本人吃的是DELPHI饭,本来在犹豫改弄VC或JAVA,现在决定选择。。。
- 关于realplayer的编程控制问题。命令行或者real的api 急在线等待
- -----200分-------我的程序出大问题了,救救我!
- 急,activex 与WM_MOUSEWHEEL事件
- 我是一个普通大学的普通学生,学计算机,有c++的基础,现在想学vc,应该从什么书看起?
- 求救!Incorrect syntax near the keyword 'clustered'错误
- 请帮忙csv文件格式
我有例子,告诉我你的邮箱。
int CGetIPDlg::GetIPAddress(const CString& sHostName, CString& sIPAddress)
{
struct hostent FAR *lpHostEnt = gethostbyname (sHostName);if (lpHostEnt == NULL) {
// An error occurred.
sIPAddress = _T("");
return WSAGetLastError();
}LPSTR lpAddr = lpHostEnt->h_addr_list[0];
if (lpAddr) {
struct in_addr inAddr;
memmove (&inAddr, lpAddr, 4);
sIPAddress = inet_ntoa (inAddr);
if (sIPAddress.IsEmpty())
sIPAddress = _T("Not available");
} return 0;
}
char *host;
struct hostent * hostinfohostinfo = gethostbyname(host);
if(!hostinfo) return;hostinfo->h_aliases; //为主机IP
ping 主机名
hostent *Me_Info=NULL;
Me_Info=gethostbyname(m_user);
if(Me_Info!=NULL)
inet_ntoa(*(struct in_addr*)Me_Info->h_addr_list[0]); //IP Address