Android Question How to get MAC Address and IP Address of the Mobile Device in the Application

beelze69

Active Member
Licensed User
Longtime User
Hi,

I have a doubt.

Would like to know how to get the 'Mac Address' and 'IP Address' of the mobile device in my application
when the user invokes my application on that mobile device.


Thanks.
 

beelze69

Active Member
Licensed User
Longtime User
You cannot get the mac address on new devices.

You can get the ip address with ServerSocket from Network library. Note that you don't need to Initialize ServerSocket for this (ignore the warning).
Hi Erel,

Thanks for the info.,

I have tried your solution and it works !

However, the requirement is for an application which will be accessible only by certain mobile devices provided officially.

Application should not allow 'unofficial' mobile devices to access it.


Hence I thought MAC Address capturing would be a good solution.

IP Address (even if I fix it via the Static IP option on the Wifi Router) can be 'changed' by any person who has access to the WiFi Router and is not a very fool-proof solution.

Is there any other option - basically I want only specific mobile devices to access the application..


Thanks,
 
Last edited:
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
I just noticed on my Samsung Galaxy S20 Ultra (Android 11) under WiFi Settings Mac1.jpgyou can select a Random MAC or the Real Phone MAC.
Would this have any bearing on the MAC returned to an App?


Mac1.jpg
 
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
It certainly seems the Settings App can retrieve the true MAC address.
Provided I select 'Phone MAC' rather than 'Random MAC', The address displayed on the phone is the MAC address as seen by my WiFi router.

I'm on Android 11 on a Samsung Galaxy S20 - A 'New' device.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Hence I thought MAC Address capturing would be a good solution.
Newer devices (particularly mobile devices) use "MAC Address Randomization" (Google it) so the machine does not have a unique MAC address. This is done on purpose to make tracking more difficult.
 
Upvote 0

MikeSW17

Active Member
Licensed User
Longtime User
Newer devices (particularly mobile devices) use "MAC Address Randomization" (Google it) so the machine does not have a unique MAC address. This is done on purpose to make tracking more difficult.

My 'Settings' App has two options 'Randomized MAC' and 'Phone MAC' (as shown in the screen capture in post #6 above)
This is Android 11 on a Samsung Galaxy S20.

When I select 'Phone MAC', a MAC address is shown on the phone (in Settings) that matches the MAC address as seen by my router.

That there is a 'Real' MAC on the phone is undeniable.

Also, both the 'Randomized MAC' and 'Phone MAC' addresses persist across device power off/on.

It certainly seems that when 'Phone MAC' is selected, it is a Unique identification - at least as WiFi access points see it.
At this stage, I haven't written a B4A App (lack of knowledge/time yet) to see what MAC addresses are seen on the device by a user app under each of the options.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
"That there is a 'Real' MAC on the phone is undeniable. "
That is true but is mostly useless since most of the time the device will report a different MAC address when you access a different access point, unless MAR is turned off.

In addition, on the devices I am familiar with, the hardware MAC address is different on 2.4GHz and 5GHz (aside from MAR), I suspect that is the case for all devices since both radios are somewhat independent and could be on at the same time so while they are actual hardware MAC addresses and are unique to their particular interface, you can't use it to uniquely identify a device (phone, tablet, laptop) unless you register both MAC addresses. If you use a USB-WiFi adapter on a laptop, you will get yet another MAC address.
Bottom line, you would be better off trying to find another method of identification because that is not likely to work very well, hence I propose a modification to Erel's post: " You cannot <reliably> get the mac address on new devices. "
 
Upvote 0
Top