PTUSERIO.CPP
上传用户:jencksen
上传日期:2016-04-08
资源大小:66k
文件大小:3k
源码类别:

ICQ弱点检测代码

开发平台:

Visual C++

  1. //////////////////////////////////////////////////////////
  2. // PTUSERIO.CPP文件
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <ntddndis.h>
  6. #include "../driver/IOCOMMON.h"
  7. #include "ptutils.h"
  8. void DisplayAdapterInfo(HANDLE hAdapter)
  9. {
  10. char buffer[1024 + sizeof(PTUSERIO_OID_DATA) - 1];
  11. PPTUSERIO_OID_DATA pOid = (PPTUSERIO_OID_DATA)buffer;
  12. pOid->Length = 1024;
  13. // 查询制造商的描述信息
  14. pOid->Oid = OID_GEN_VENDOR_DESCRIPTION;
  15. pOid->Length = 1024;
  16. if(!PtAdapterRequest(hAdapter, pOid, TRUE))
  17. {
  18. printf(" PtAdapterRequest() failed n ");
  19. return;
  20. }
  21. wprintf(L" Description: %S n", (LPWSTR)pOid->Data);
  22. // 查询正在使用的媒介
  23. NDIS_MEDIUM NdisMedium;
  24. pOid->Oid = OID_GEN_MEDIA_IN_USE;
  25. pOid->Length = 1024;
  26. if(!PtAdapterRequest(hAdapter, pOid, TRUE))
  27. {
  28. printf(" PtAdapterRequest() failed n ");
  29. return;
  30. }
  31. NdisMedium = *((PNDIS_MEDIUM )pOid->Data);
  32. switch(NdisMedium)
  33. {
  34. case NdisMedium802_3:
  35. printf(" Medium: NdisMedium802_3 n");
  36. break;
  37. case NdisMediumWan:
  38. printf(" Medium: NdisMediumWan n");
  39. break;
  40. default:
  41. printf(" unkown type n");
  42. break;
  43. }
  44. // 查询连接状态
  45. int nConnectedState;
  46. pOid->Oid = OID_GEN_MEDIA_CONNECT_STATUS;
  47. pOid->Length = 1024;
  48. if(!PtAdapterRequest(hAdapter, pOid, TRUE))
  49. {
  50. printf(" Media Connect Status: UNKNOWN n ");
  51. }
  52. else
  53. {
  54. nConnectedState = *((int*)pOid->Data);
  55. printf( " Media Connect Status: %sn",
  56.          nConnectedState == NdisMediaStateConnected ? "Connected" : "Disconnected");
  57. }
  58. }
  59. int main()
  60. {
  61. HANDLE hControlDevice = PtOpenControlDevice();
  62. CIMAdapters adapters;
  63. if(!adapters.EnumAdapters(hControlDevice))
  64. {
  65. printf(" EnumAdapters failed n");
  66. return -1;
  67. }
  68. printf(" Driver Bindings: n");
  69. for(int i=0; i<adapters.m_nAdapters; i++)
  70. {
  71. // 显示虚拟适配器名称
  72. printf("    "%ws" n", adapters.m_pwszVirtualName[i]);
  73. // 显示下层适配器名称
  74. printf("       "%ws" n", adapters.m_pwszAdapterName[i]);
  75. HANDLE hLowerAdapter = PtOpenAdapter(adapters.m_pwszAdapterName[i]);
  76. if(hLowerAdapter != INVALID_HANDLE_VALUE)
  77. {
  78. DisplayAdapterInfo(hLowerAdapter);
  79. ::CloseHandle(hLowerAdapter);
  80. }
  81. printf(" n");
  82. }
  83. ::CloseHandle(hControlDevice);
  84. return 0;
  85. }
  86. /*
  87. int main()
  88. {
  89. HANDLE hControlDevice = PtOpenControlDevice();
  90. CIMAdapters adapters;
  91. if(!adapters.EnumAdapters(hControlDevice))
  92. {
  93. printf(" EnumAdapters failed n");
  94. return -1;
  95. }
  96. printf(" Driver Bindings: n");
  97. for(int i=0; i<adapters.m_nAdapters; i++)
  98. {
  99. // 显示虚拟适配器名称
  100. printf("    42%ws42n", adapters.m_pwszVirtualName[i]);
  101. // 显示下层适配器名称
  102. printf("       42%ws42n", adapters.m_pwszAdapterName[i]);
  103. printf(" n");
  104. }
  105. ::CloseHandle(hControlDevice);
  106. return 0;
  107. }
  108. */