Advertisement
Guest User

test

a guest
Jan 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "iostream"
  3. #include "windows.h"
  4. #include "iphlpapi.h"
  5. #include "cstdlib"
  6.  
  7. #pragma comment (lib, "IPHlpApi.Lib")
  8. #pragma comment (lib, "WSock32.Lib")
  9.  
  10. using namespace std;
  11.  
  12. void ShowAdaprets(PIP_ADAPTER_INFO);
  13.  
  14. int main()
  15. {
  16. system("chcp 1251");
  17. system("cls");
  18. ULONG buff = sizeof(IP_ADAPTER_INFO);
  19. PIP_ADAPTER_INFO buffAdapter = (PIP_ADAPTER_INFO)malloc(buff);
  20. if (GetAdaptersInfo(buffAdapter, &buff) == ERROR_BUFFER_OVERFLOW)
  21. {
  22. free(buffAdapter);
  23. buffAdapter = (PIP_ADAPTER_INFO)malloc(buff);
  24. }
  25. if (GetAdaptersInfo(buffAdapter, &buff) != ERROR_SUCCESS)
  26. {
  27. free(buffAdapter);
  28. return 0;
  29. }
  30. PIP_ADAPTER_INFO AdapterInfo = buffAdapter;
  31. int cntr = 1;
  32. while (AdapterInfo != NULL)
  33. {
  34. ShowAdaprets(AdapterInfo);
  35. AdapterInfo = AdapterInfo->Next;
  36. cntr++;
  37. }
  38. free(buffAdapter);
  39. getchar();
  40. return 0;
  41. }
  42.  
  43. void ShowAdaprets(PIP_ADAPTER_INFO pAdapterInfo)
  44. {
  45. static int c = 1;
  46. cout << "Network adapter " << c << endl;
  47. cout << "Adapter name: " << pAdapterInfo->AdapterName << endl;
  48. cout << "Adapter description: " << pAdapterInfo->Description << endl;
  49. IP_ADDR_STRING* IP = &(pAdapterInfo->IpAddressList);
  50. while (IP != NULL)
  51. {
  52. cout << "IP: " << IP->IpAddress.String << endl;
  53. cout << "Mask: " << IP->IpMask.String << endl;
  54. IP = IP->Next;
  55. }
  56. IP = &(pAdapterInfo->GatewayList);
  57. while (IP != NULL)
  58. {
  59. cout << "Gateway: " << IP->IpAddress.String << endl;
  60. IP = IP->Next;
  61. }
  62. cout << endl;
  63. c++;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement