Hi Is there any way to get the mac addresses of Android and Iphone devices? I have tried with for(var stuff : NetworkInterface in NetworkInterface.GetAllNetworkInterfaces()) { if (stuff.OperationalStatus == OperationalStatus.Up) { var macAddress = stuff.GetPhysicalAddress().ToString(); } print(macAddress); } But it prints 4 things, only one of them the mac address and this is just for pc. Thanks
Okey I got the mac address from my pc with this: Code (csharp): for(var stuff : NetworkInterface in NetworkInterface.GetAllNetworkInterfaces()) { if (stuff.OperationalStatus == OperationalStatus.Up) { var macAddress = stuff.GetPhysicalAddress().ToString(); if(!macAddress.StartsWith("0000") macAddress!="") { print(macAddress); } } } But it does not work with android, I can imagine that it should look totaly different for Android and Iphone, but I have found nothing about it.
I was wondering the same thing, can you by any chance post the whole script that worked on your PC, the script as it is cannot run on it's own. It would be great also if it could work on both iOS and Android. Right now I have found a way in pure C for iOS but I don't know how to make it work with Unity3D and if it can be used on Android as well. If anybody can find more informations it will be very appreciated.
Hey guys! I found the solution. This code works on MacOS and on iOS. I haven't tested on Android. Code (csharp): // Returns the 1st valid Mac Address function GetMacAddress(){ var macAdress = ""; var nics : NetworkInterface[] = NetworkInterface.GetAllNetworkInterfaces(); var i = 0; for (var adapter: NetworkInterface in nics){ var address: PhysicalAddress = adapter.GetPhysicalAddress(); if(address.ToString() != ""){ macAdress = address.ToString(); return macAdress; } } return 0; } Cheers! Good Luck on your project!
This works great just don't forget at the top. EDIT:: Still doesn't work on my kindle fire but works correctly on my PC....hmm
One solution for Android devices, using Unity's AndroidJavaObject constructor: Code (csharp): AndroidJavaObject mWiFiManager; string ReturnMacAddress() { string macAddr = ""; if (mWiFiManager == null) { using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity")) { mWiFiManager = activity.Call<AndroidJavaObject>("getSystemService","wifi"); } } macAddr = mWiFiManager.Call<AndroidJavaObject>("getConnectionInfo").Call<string>("getMacAddress" return macAddr; } Note, this only returns a valid MAC address if the WiFi adapter is already enabled on the device.
Hello sorry for keep wth this thread, but Im still unable to access the mac of my android device from unity. I think your answer is the most aproximate to the solution but I still can't access the mac of the device, ¿Please can someone help me?
Hello, I can't make this work, this part is not recognised on mono develop: AndroidJavaObject mWiFiManager;
I dont know exactly how people feel about resurrecting dead threads but I would recommend creating your own one thread as this usually annoys people on forums.
I hope this help in unity go to Assets => Plugins => Android => AndroidManifest.xml and add this line of Code as permissions <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> and script Code (CSharp): AndroidJavaObject mWiFiManager; string ReturnMacAddress() { string macAddr = ""; if (mWiFiManager == null) { using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity")) { mWiFiManager = activity.Call<AndroidJavaObject>("getSystemService","wifi"); } } macAddr = mWiFiManager.Call<AndroidJavaObject>("getConnectionInfo").Call<string>("getMacAddress"); return macAddr; }
Работает на 7-м Анройде а на 6-м по прежнему хуй... =( public void DisplayTypeAndAddress() { NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); txt.text = txt.text + (nics.Length + " nics").ToString() + "\n"; foreach (NetworkInterface adapter in nics) { IPInterfaceProperties properties = adapter.GetIPProperties(); txt.text = txt.text + (adapter.Description).ToString() + "\n"; txt.text = txt.text + (String.Empty.PadLeft(adapter.Description.Length, '=')).ToString() + "\n"; txt.text = txt.text + (" Interface type .......................... :" + adapter.NetworkInterfaceType) + "\n"; txt.text = txt.text + (" Physical Address ........................ :" + adapter.GetPhysicalAddress()) + "\n"; txt.text = txt.text + (" Is receive only.......................... :" + adapter.IsReceiveOnly) + "\n"; txt.text = txt.text + (" Multicast................................ :" + adapter.SupportsMulticast) + "\n"; } }
@APGame Hi, I would like to point out that I was using @master2001 solution, which worked fine on my testing device (Android 4.0), but after testing in others devices and some research I found this code it is not working anymore on Android 6.0+. Unfortunately, I didn´t find another way to retrieve the Mac Address, but in my case I needed a unique identifier for each device, so the solution I found (although it is not the best one, it is the most reliable at the moment) is quite simple, use https://docs.unity3d.com/ScriptReference/SystemInfo-deviceUniqueIdentifier.html instead. I took the solution from here: http://answers.unity3d.com/questions/659273/how-to-find-mac-address-in-ios-and-android.html. Hope this helps you or somebody else.
I have search this solution for a long time, there is no way that i can find to sovle this problem by Using Unity API, the way i take is building plugins to Android/IOS. if anyone know the solution to sovle this issue, I am glad to hear from you~~