Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- #include "windows.h"
- #include "iphlpapi.h"
- #include "cstdlib"
- #pragma comment (lib, "IPHlpApi.Lib")
- #pragma comment (lib, "WSock32.Lib")
- using namespace std;
- void ShowAdaprets(PIP_ADAPTER_INFO);
- int main()
- {
- system("chcp 1251");
- system("cls");
- ULONG buff = sizeof(IP_ADAPTER_INFO);
- PIP_ADAPTER_INFO buffAdapter = (PIP_ADAPTER_INFO)malloc(buff);
- if (GetAdaptersInfo(buffAdapter, &buff) == ERROR_BUFFER_OVERFLOW)
- {
- free(buffAdapter);
- buffAdapter = (PIP_ADAPTER_INFO)malloc(buff);
- }
- if (GetAdaptersInfo(buffAdapter, &buff) != ERROR_SUCCESS)
- {
- free(buffAdapter);
- return 0;
- }
- PIP_ADAPTER_INFO AdapterInfo = buffAdapter;
- int cntr = 1;
- while (AdapterInfo != NULL)
- {
- ShowAdaprets(AdapterInfo);
- AdapterInfo = AdapterInfo->Next;
- cntr++;
- }
- free(buffAdapter);
- getchar();
- return 0;
- }
- void ShowAdaprets(PIP_ADAPTER_INFO pAdapterInfo)
- {
- static int c = 1;
- cout << "Network adapter " << c << endl;
- cout << "Adapter name: " << pAdapterInfo->AdapterName << endl;
- cout << "Adapter description: " << pAdapterInfo->Description << endl;
- IP_ADDR_STRING* IP = &(pAdapterInfo->IpAddressList);
- while (IP != NULL)
- {
- cout << "IP: " << IP->IpAddress.String << endl;
- cout << "Mask: " << IP->IpMask.String << endl;
- IP = IP->Next;
- }
- IP = &(pAdapterInfo->GatewayList);
- while (IP != NULL)
- {
- cout << "Gateway: " << IP->IpAddress.String << endl;
- IP = IP->Next;
- }
- cout << endl;
- c++;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement