- 5
- 0
- 约3.79千字
- 约 6页
- 2018-06-07 发布于未知
- 举报
VC++之网络通信技术之获取局域网其它计算机的IP地址
2010年11月22日 星期一 21:59
一、创建对话框应用程序
二、编辑对话框资源
控件ID及标题
IDC_LIST_IP
IDC_GETOTHERIP????????????????????????????????????获取局域网其它计算机的IP地址(属性有“浮动”)
三、添加变量、函数
??????? 1、添加变量
??????? 2、添加消息响应函数
四、添加代码
????????? 1、于“GetOtherIPDlg.cpp”文件内添加包含语句
#include stdafx.h#include GetOtherIP.h#include GetOtherIPDlg.h
#include Winsock2.h
????????? 2、于“GetOtherIPDlg.cpp”文件内添加消息响应函数代码
void CGetOtherIPDlg::OnGetotherip() {// TODO: Add your control notification handler code herestruct hostent *host; struct in_addr *ptr; // 检索IP地址 DWORD dwScope = RESOURCE_CONTEXT; NETRESOURCE *NetResource = NULL; HANDLE hEnum; WNetOpenEnum( dwScope, NULL, NULL, NULL, hEnum ); WSADATA wsaData; WSAStartup(MAKEWORD(1,1),wsaData); CString strTemp;if ( hEnum ) { ?? DWORD Count = 0xFFFFFFFF; ?? DWORD BufferSize = 2048; ?? LPVOID Buffer = new char[2048]; ?? WNetEnumResource( hEnum, Count, Buffer, BufferSize ); ?? NetResource = (NETRESOURCE*)Buffer; ?? strTemp.Format(局域网内的计算机名称及其IP地址为:);?? m_ListIP.AddString(strTemp);?? char szHostName[200]; ?? unsigned int i; ?? for ( i = 0; i BufferSize/sizeof(NETRESOURCE); i++, NetResource++ ) ?? { ??? if ( NetResource-dwUsage == RESOURCEUSAGE_CONTAINER ???? NetResource-dwType == RESOURCETYPE_ANY ) ??? { ???? if ( NetResource-lpRemoteName ) ???? { ????? CString strFullName = NetResource-lpRemoteName; ????? if ( 0 == strFullName.Left(2).Compare(\\\\) )??? ?????? strFullName = strFullName.Right(strFullName.GetLength()-2); ????? //gethostname( szHostName, strlen( szHostName ) ); ????? host = gethostbyname(strFullName); ????? if(host == NULL) continue; ????? ptr = (struct in_addr *)host-h_addr_list[0];???????????????????? ????? // =. 分隔开IP:6.????????????? ????? int a = ptr-S_un.S_un_b.s_b1; // 211??????????? ????? int b = ptr-S_un.S_un_b.s_b2; // 40 ????? int c = ptr-S_un.S_un_b.s_b3; // 35 ????? int d = ptr-S_un.S_un_b.s_b4; // 76
????? strTemp.Format( 计算机%d名称:%s--IP地址:%d.%d.%d.%d\r\n, i,strFullName,a,b,c,d); ?
您可能关注的文档
最近下载
- 2023年国家公务员考试题库含完整答案【夺冠】.docx
- 2025年甘肃省高考物理试卷(含答案解析).pdf
- 2025年深圳市中考语文试题卷(含答案解析).docx
- CECS19-1990 混凝土排水管道工程闭气检验标准.docx VIP
- 2025年广州民航职业技术学院单招笔试英语试题库含答案解析.docx VIP
- 三年级数学乘除法巧算讲解学习.docx VIP
- 波司登品牌站内种草营销方案【电商】【淘宝天猫】.pdf VIP
- 日立电梯NPM电梯安装调试说明(S-3-0418).doc VIP
- 比亚迪环境管理物质标准A6.pdf VIP
- 中数智慧:数据中心800V直流供电技术白皮书(V2.0).docx VIP
原创力文档

文档评论(0)