设为首页 加入收藏

TOP

2.3.2 具体编码(3)
2013-10-07 15:54:36 来源: 作者: 【 】 浏览:82
Tags:2.3.2 具体 编码

2.3.2  具体编码(3)

(4) 定义函数OnReceive(),用于获得扫描结果。接收各个要查询机器发回来的响应信息,并从响应信息里取出对应机器的工作组、机器名、用户名和MAC地址。

具体代码如下:

  1. void CNBTSTATDlg::OnReceive()  
  2. {     
  3. BYTE Buf[500];  
  4. CString str, strIP, strHost, strHex, strMac, Host, Group, User;  
  5. UINT dport;  
  6. m_UDPSocket.ReceiveFrom(Buf, 500, strIP, dport, 0); //接收数据  
  7. //如果接收到的IP为空或者与原来接收到的IP相同,则返回  
  8. if(strIP==(char)NULL || strIP==strOldIP) return;  
  9. strOldIP = strIP;  
  10. int index = m_ListView.InsertItem(0, strIP); //将IP插入ListView  
  11. strHost = ""; //机器名字  
  12. strHex = ""; //MAC地址  
  13. User = " ";//  
  14. Host = "\\";  
  15. int tem=0num=0;  
  16. bool bAdd = true;  
  17. //根据数据报规则取出相应的信息  
  18. for(i=57; i<500; i++) //57-72  
  19. {  
  20. if(Buf[i]==0xcc) break;   
  21. if(Buf[i]==0x20) bAdd = false;  
  22. if(bAdd)  
  23. {  
  24. str.Format("%c", Buf[i]);  
  25. if(Buf[i] >= ' ') strHost += str;  
  26. str.Format("%02x.", Buf[i]);  
  27. strHex += str;  
  28. }  
  29.  
  30. if((++tem)%18 == 0)  
  31. {  
  32. bAdd = true;   
  33. strHost.TrimRight((char)NULL);  
  34. if(strHost == "")  
  35. {  
  36. strMac.Delete(17, strMac.GetLength()-17);  
  37. m_ListView.SetItem(index, 4, LVIF_TEXT, strMac, 0, 0, 0, 0);  
  38. break;  
  39. }  
  40. if(num==0 && strHost!="")  
  41. {  
  42. m_ListView.SetItem(index, 2, LVIF_TEXT, strHost, 0, 0, 0, 0);  
  43. Host = strHost;  
  44. num++;  
  45. }  
  46. else  
  47. {  
  48. if(Host!=strHost && num==1 && strHost!="")  
  49. {  
  50. m_ListView.SetItem(index,1,LVIF_TEXT,strHost, 0, 0, 0, 0);  
  51. Group = strHost;  
  52. num++;  
  53. }  
  54. else   
  55. {  
  56. if(strHost!=Host && strHost!=Group && num==2   
  57. && strHost!="")  
  58. {  
  59. User = strHost;  
  60. if(User != "__MSBROWSE__")  
  61. {  
  62. m_ListView.SetItem(index, 3, LVIF_TEXT,  
  63. User, 0, 0, 0, 0);  
  64. num++;  
  65. }  
  66. }  
  67. }  
  68. }  
  69. strMac = strHex;  
  70. strHost = "";  
  71. strHex = "";  
  72. }  
  73. }  
  74. //触发事件,导致线程函数的继续执行  
  75. SetEvent(wait_handle);  
  76. }  

到此为止,整个项目中的核心模块已经介绍完毕,至于其他次要部分代码,请读者参考本书附带光盘中的源代码。执行之后的效果如图2-17所示。
 
图2-17  执行效果
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇2.3.2 具体编码(2) 下一篇3.1 FTP能带给我们什么

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C++中智能指针的性能 (2025-12-25 03:49:29)
·如何用智能指针实现c (2025-12-25 03:49:27)
·如何在 C 语言中管理 (2025-12-25 03:20:14)
·C语言和内存管理有什 (2025-12-25 03:20:11)
·为什么C语言从不被淘 (2025-12-25 03:20:08)