如何获取 mac 地址
How to get mac address
我正在开发一个在 hololens2 上运行的 uwp 应用程序,我想获取 wifi mac 地址。
根据文档:Windows.Networking,我写了这段代码。
// part of includes at pch.h
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.ApplicationModel.Core.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Foundation.Metadata.h>
#include <winrt/Windows.Data.Xml.Dom.h>
#include <winrt/Windows.Devices.h>
#include <winrt/Windows.Devices.WiFi.h>
#include <winrt/Windows.Devices.WiFiDirect.h>
#include <winrt/Windows.Devices.Sms.h>
#include <winrt/Windows.Networking.h>
#include <winrt/Windows.Networking.BackgroundTransfer.h>
#include <winrt/Windows.Networking.Connectivity.h>
#include <winrt/Windows.Networking.NetworkOperators.h>
#include <winrt/Windows.Networking.Proximity.h>
#include <winrt/Windows.Networking.PushNotifications.h>
#include <winrt/Windows.Networking.ServiceDiscovery.Dnssd.h>
#include <winrt/Windows.Networking.Sockets.h>
#include <winrt/Windows.Networking.Vpn.h>
// some cpp function
void MainPage::ClickLoginHandler(IInspectable const&, RoutedEventArgs const&)
{
using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Windows::Networking;
using namespace winrt::Windows::Networking::Connectivity;
using namespace winrt::Windows::Networking::NetworkOperators;
ConnectionProfile profile = NetworkInformation::GetInternetConnectionProfile();
NetworkOperatorTetheringManager manager =
NetworkOperatorTetheringManager::CreateFromConnectionProfile(profile); // error on the line
IVectorView<NetworkOperatorTetheringClient> clients = manager.GetTetheringClients();
for (NetworkOperatorTetheringClient client : clients)
{
OutputDebugString(client.MacAddress().c_str());
OutputDebugString(L"\r\n");
}
}
但报错:WinRT originate error - 0x8007007F : 'The specified procedure could not be found.'。
似乎缺少dll,我找不到哪一个或两个?
如果你知道请告诉我。
如果您知道其他获取 mac 地址的方法,请告诉我。
谢谢
How to get mac address for hololens2.
对于这种情况,您可以使用您可以参考的GetAdaptersAddresses
method to approach. The document has simple code。
我正在开发一个在 hololens2 上运行的 uwp 应用程序,我想获取 wifi mac 地址。
根据文档:Windows.Networking,我写了这段代码。
// part of includes at pch.h
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.ApplicationModel.Core.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Foundation.Metadata.h>
#include <winrt/Windows.Data.Xml.Dom.h>
#include <winrt/Windows.Devices.h>
#include <winrt/Windows.Devices.WiFi.h>
#include <winrt/Windows.Devices.WiFiDirect.h>
#include <winrt/Windows.Devices.Sms.h>
#include <winrt/Windows.Networking.h>
#include <winrt/Windows.Networking.BackgroundTransfer.h>
#include <winrt/Windows.Networking.Connectivity.h>
#include <winrt/Windows.Networking.NetworkOperators.h>
#include <winrt/Windows.Networking.Proximity.h>
#include <winrt/Windows.Networking.PushNotifications.h>
#include <winrt/Windows.Networking.ServiceDiscovery.Dnssd.h>
#include <winrt/Windows.Networking.Sockets.h>
#include <winrt/Windows.Networking.Vpn.h>
// some cpp function
void MainPage::ClickLoginHandler(IInspectable const&, RoutedEventArgs const&)
{
using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Windows::Networking;
using namespace winrt::Windows::Networking::Connectivity;
using namespace winrt::Windows::Networking::NetworkOperators;
ConnectionProfile profile = NetworkInformation::GetInternetConnectionProfile();
NetworkOperatorTetheringManager manager =
NetworkOperatorTetheringManager::CreateFromConnectionProfile(profile); // error on the line
IVectorView<NetworkOperatorTetheringClient> clients = manager.GetTetheringClients();
for (NetworkOperatorTetheringClient client : clients)
{
OutputDebugString(client.MacAddress().c_str());
OutputDebugString(L"\r\n");
}
}
但报错:WinRT originate error - 0x8007007F : 'The specified procedure could not be found.'。
似乎缺少dll,我找不到哪一个或两个?
如果你知道请告诉我。
如果您知道其他获取 mac 地址的方法,请告诉我。
谢谢
How to get mac address for hololens2.
对于这种情况,您可以使用您可以参考的GetAdaptersAddresses
method to approach. The document has simple code。