{"id":4171,"date":"2025-06-16T13:20:19","date_gmt":"2025-06-16T11:20:19","guid":{"rendered":"https:\/\/www.capri-soft.de\/blog\/?p=4171"},"modified":"2025-06-16T13:25:51","modified_gmt":"2025-06-16T11:25:51","slug":"c-list-all-network-devices-with-their-properties-attributes-like-guid-adapter-name-mac-address-description","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=4171","title":{"rendered":"C : List all network devices with their properties \/ attributes like GUID, adapter name, MAC address, Description"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Problem<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In some cases mighty libs like NPCap or WinPCap are used to get a list of all network devices with common properties like GUID and so on. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Approach<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><code>#pragma comment(lib, \"iphlpapi.lib\")<\/code><\/strong><br>This links the&nbsp;<strong>IP Helper API<\/strong>&nbsp;library, which provides functions for retrieving network configuration and statistics, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Network adapter information<\/li>\n\n\n\n<li>IP address tables<\/li>\n\n\n\n<li>Routing tables<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><code>#pragma comment(lib, \"ws2_32.lib\")<\/code><\/strong><br>This links the&nbsp;<strong>Winsock 2<\/strong>&nbsp;library, which is essential for network programming on Windows. It provides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Socket APIs for TCP\/UDP communication<\/li>\n\n\n\n<li>DNS resolution<\/li>\n\n\n\n<li>Network initialization and cleanup functions<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Solution<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;winsock2.h&gt;\n#include &lt;iphlpapi.h&gt;\n#include &lt;ws2tcpip.h&gt;\n\n#pragma comment(lib, &quot;iphlpapi.lib&quot;)\n#pragma comment(lib, &quot;ws2_32.lib&quot;)\n\nint main() {\n    DWORD dwSize = 0;\n    DWORD dwRetVal = 0;\n\n    IP_ADAPTER_ADDRESSES *pAddresses = NULL;\n    IP_ADAPTER_ADDRESSES *pCurrAddresses = NULL;\n\n    ULONG flags = GAA_FLAG_INCLUDE_PREFIX;\n    ULONG family = AF_UNSPEC;\n\n    \/\/ Erste Abfrage zur Bestimmung der Puffergr\u00f6\u00dfe\n    dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &amp;dwSize);\n    if (dwRetVal == ERROR_BUFFER_OVERFLOW) {\n        pAddresses = (IP_ADAPTER_ADDRESSES *) malloc(dwSize);\n        if (pAddresses == NULL) {\n            printf(&quot;Speicher konnte nicht reserviert werden.\\n&quot;);\n            return 1;\n        }\n    }\n\n    \/\/ Zweiter Aufruf mit g\u00fcltigem Puffer\n    dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &amp;dwSize);\n    if (dwRetVal == NO_ERROR) {\n        pCurrAddresses = pAddresses;\n        while (pCurrAddresses) {\n            printf(&quot;Adapter GUID: %s\\n&quot;, pCurrAddresses-&gt;AdapterName);\n            printf(&quot;Adaptername: %ws\\n&quot;, pCurrAddresses-&gt;FriendlyName);\n            printf(&quot;Beschreibung: %ws\\n&quot;, pCurrAddresses-&gt;Description);\n            if (pCurrAddresses-&gt;PhysicalAddressLength != 0) {\n                printf(&quot;MAC-Adresse: &quot;);\n                for (DWORD i = 0; i &lt; pCurrAddresses-&gt;PhysicalAddressLength; i++) {\n                    printf(&quot;%02X&quot;, pCurrAddresses-&gt;PhysicalAddress&#x5B;i]);\n                    if (i &lt; pCurrAddresses-&gt;PhysicalAddressLength - 1)\n                        printf(&quot;:&quot;);\n                }\n                printf(&quot;\\n&quot;);\n            }\n            \n            printf(&quot;--------------------------------------------------\\n&quot;);\n            pCurrAddresses = pCurrAddresses-&gt;Next;\n        }       \n    } else {\n        printf(&quot;GetAdaptersAddresses fehlgeschlagen mit Fehler: %lu\\n&quot;, dwRetVal);\n    }\n\n    if (pAddresses) {\n        free(pAddresses);\n    }\n\n    return 0;\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">PS C:\\Betriebssysteme\\\u00dcbung 6&gt; .\\ListNetworkDevices  <br>Adapter GUID: {E01CE7A3-099B-4184-8C16-1F5054A8317F}<br>Adaptername: Ethernet<br>Beschreibung: Intel(R) Ethernet Connection (7) I219-LM<br>MAC-Adresse: 34:48:ED:61:86:BA<br>--------------------------------------------------<br>Adapter GUID: {4012AE18-3341-4541-892C-BC0286FA6504}<br>Adaptername: Ethernet 2<br>Beschreibung: Check Point Virtual Network Adapter For Endpoint VPN Client<br>MAC-Adresse: 54:DF:6F:F5:98:06<br>--------------------------------------------------<br>Adapter GUID: {6EFE57EA-027E-45AA-9BFD-8071CE36C5FD}<br>Adaptername: Ethernet 7<br>Beschreibung: VirtualBox Host-Only Ethernet Adapter<br>MAC-Adresse: 0A:00:27:00:00:0F<br>--------------------------------------------------<br>Adapter GUID: {1A8FA3D8-A753-4453-8362-78FA3A6B314C}<br>Adaptername: Local Area Connection* 1<br>Beschreibung: Microsoft Wi-Fi Direct Virtual Adapter<br>MAC-Adresse: B8:9A:2A:2F:51:8F<br>--------------------------------------------------<br>Adapter GUID: {4BE430BD-CB19-4CBB-BA70-0D4EE0F6AECE}<br>Adaptername: Local Area Connection* 2<br>Beschreibung: Microsoft Wi-Fi Direct Virtual Adapter #2<br>MAC-Adresse: BA:9A:2A:2F:51:8E<br>--------------------------------------------------<br>Adapter GUID: {DFDC464C-3487-4D61-B1AE-28733CA18E2E}<br>Adaptername: Wi-Fi<br>Beschreibung: Intel(R) Wi-Fi 6 AX200 160MHz<br>MAC-Adresse: B8:9A:2A:2F:51:8E<br>--------------------------------------------------<br>Adapter GUID: {BAA489E2-AF2D-4A75-A99C-2E4C19B04F44}<br>Adaptername: Bluetooth Network Connection<br>Beschreibung: Bluetooth Device (Personal Area Network)<br>MAC-Adresse: B8:9A:2A:2F:51:92<br>--------------------------------------------------<br>Adapter GUID: {88CB09EB-7A9D-11EF-986B-806E6F6E6963}<br>Adaptername: Loopback Pseudo-Interface 1<br>Beschreibung: Software Loopback Interface 1<br>--------------------------------------------------<br>PS C:\\Betriebssysteme\\\u00dcbung 6&gt; <\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D4171&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Problem In some cases mighty libs like NPCap or WinPCap are used to get a list of all network devices with common properties like GUID and so on. Approach #pragma comment(lib, &#8222;iphlpapi.lib&#8220;)This links the&nbsp;IP Helper API&nbsp;library, which provides functions for retrieving network configuration and statistics, such as: #pragma comment(lib, &#8222;ws2_32.lib&#8220;)This links the&nbsp;Winsock 2&nbsp;library, which is &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=4171\" class=\"more-link\"><span class=\"screen-reader-text\">C : List all network devices with their properties \/ attributes like GUID, adapter name, MAC address, Description<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[516,552,3],"tags":[553],"class_list":["post-4171","post","type-post","status-publish","format-standard","hentry","category-betriebssysteme","category-c-programmierung-2","category-programmierung","tag-list-network-adapters"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-15h","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4171"}],"version-history":[{"count":3,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4171\/revisions"}],"predecessor-version":[{"id":4175,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4171\/revisions\/4175"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}