• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Android get MAC address from device IP Address

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Previously, I have used proc/net/arp to find other devices on the network. API 29 does not give an application access to this file any longer. Also, it is more difficult to find the host device's MAC address. I am able to find device IP addresses on the current network by scanning for services where devices will broadcast themselves. From this I am able to make a list of IP addresses active on the current network. How do I resolve a MAC address on Android after API 29. I have tried:  



but this will only get the MAC address from the device I run it on. If I have an IP address of another device on the subnet, how can I resolve its MAC address?

 
Saloon Keeper
Posts: 13014
281
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Why do you need the MAC address? Programmatic access was removed for a reason.
 
Saloon Keeper
Posts: 6994
164
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are good reasons for wanting to get the MAC addresses of networked devices - Wake-On-Lan for example.

The output of the "ip" command (which you can run via Runtime.exec) has all kinds of useful information. "ip addr" has more data than you'll get from NetworkInterface, for example. "ip neigh show" has MAC addresses of known hosts on the same network, especially after doing a subnet scan (meaning, making connections to those hosts).

Android API 30 curtails the "ip" command, unfortunately, also in the name of protecting MAC addresses. I have not found a workaround, so it may be gone for good.
 
Saloon Keeper
Posts: 23774
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know about Wake-on-LAN for Android devices. For one thing, I've gotten the impression that Android has been downplaying its Linux underpinnings of late.

A more practical need, however, would be to restrict access to a a sensitive wireless access point. Some WAP routers allow defining whitelists and/or blacklists of authorized client MAC addresses. For that matter, so do some wired routers.

On the other hand, I was reviewing Bluetooth Low Energy security this morning and was interested to learn that some BLE implementations can dynamically/randomly change their transceiver "MAC" addresses as a foil against identity tracking. Which is to say, for example, to be able to follow someone around by tailing their fixed MAC address. So similar logic may be in play for TCP/IP interfaces.
 
Tom Pryer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Welcome to CodeRanch!

Why do you need the MAC address? Programmatic access was removed for a reason.



I'm making a network scanning app on Android to keep track of devices on your network with WOL support as well as other features.

Tim Moores wrote:There are good reasons for wanting to get the MAC addresses of networked devices - Wake-On-Lan for example.

The output of the "ip" command (which you can run via Runtime.exec) has all kinds of useful information. "ip addr" has more data than you'll get from NetworkInterface, for example. "ip neigh show" has MAC addresses of known hosts on the same network, especially after doing a subnet scan (meaning, making connections to those hosts).

Android API 30 curtails the "ip" command, unfortunately, also in the name of protecting MAC addresses. I have not found a workaround, so it may be gone for good.



Thank you! In what way does API 30 restrict the ip command? I can't seem to find anything about this in release notes.
 
Tim Holloway
Saloon Keeper
Posts: 23774
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if you can browse /sys/dev/*/address files.
 
Tim Moores
Saloon Keeper
Posts: 6994
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:See if you can browse /sys/dev/*/address files.


That's not permitted on unrooted devices.
 
Tim Moores
Saloon Keeper
Posts: 6994
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tom Pryer wrote:In what way does API 30 restrict the ip command? I can't seem to find anything about this in release notes.


https://developer.android.com/training/articles/user-data-ids#mac-11-plus

I'm making a network scanning app on Android to keep track of devices on your network with WOL support as well as other features.


There are good apps out there for that, like PingTools and it's Pro version which is well worth its price. Ping & Net lets you create widgets for WOL-ing particular hosts.
 
Tim Holloway
Saloon Keeper
Posts: 23774
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:On the other hand, I was reviewing Bluetooth Low Energy security this morning and was interested to learn that some BLE implementations can dynamically/randomly change their transceiver "MAC" addresses as a foil against identity tracking. Which is to say, for example, to be able to follow someone around by tailing their fixed MAC address. So similar logic may be in play for TCP/IP interfaces.



And it seems that it's not just for Bluetooth, as of Android 10: https://source.android.com/devices/tech/connect/wifi-mac-randomization
 
Stephan van Hulst
Saloon Keeper
Posts: 13014
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tom Pryer wrote:I'm making a network scanning app on Android to keep track of devices on your network with WOL support as well as other features.


You have to understand that the reason programmatic access was removed is exactly because Android doesn't want you to be able to track devices. Even if you find some way to do it now, you can be sure that they will plug that hole as soon as possible.

The only thing you can hope for is that Android will at some point add some special permission that users can grant to apps to let the apps track them. Anything other than that will not be future-proof and is fighting against the user's right to privacy.
 
Tim Moores
Saloon Keeper
Posts: 6994
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:

Tom Pryer wrote:I'm making a network scanning app on Android to keep track of devices on your network with WOL support as well as other features.


Android doesn't want you to be able to track devices.... fighting against the user's right to privacy.


There's a difference between "tracking" and "keeping track", so I don't think the two of you are talking about the same thing. For a company it's quite natural (and legitimate) to keep track of devices on its network, and user privacy doesn't figure into that at all. Especially as I would guess that the devices in question are mostly desktop and server machines, not mobile devices - note the mention of WOL, which makes no sense for a mobile device.
 
Tim Holloway
Saloon Keeper
Posts: 23774
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I couldn't use a tool like this anyway. You can't map a network by MAC address (which is probably best done using arp, anyway. MAC addresses are local to LAN segments. The mousetech.com network has  separate wireless segments, a WAN segment, and 2 wired LAN segments, and that's not especially complex for a business environment.

Also, offhand, I don't know how to probe for WOL capability. My understanding is that's it's done via UDP packets outbound and I know of no protocols that can reliably query. Not that I've looked. But absent that, the best I could come up with would be to ping an IP to make sure it's down, send WOL, ping again to see if anything woke up. And that forces the target awake (though it's hard to query a sleeping target anyway). Plus, DHCP would make such a scheme more difficult still.
 
Stephan van Hulst
Saloon Keeper
Posts: 13014
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:There's a difference between "tracking" and "keeping track", so I don't think the two of you are talking about the same thing.


It's literally the same thing. And yes, it IS a privacy concern.

For a company it's quite natural (and legitimate) to keep track of devices on its network, and user privacy doesn't figure into that at all.


It may be legitimate, but it's no longer natural. Privacy does figure into all of this. The Open Handset Alliance seems to agree.

Especially as I would guess that the devices in question are mostly desktop and server machines, not mobile devices - note the mention of WOL, which makes no sense for a mobile device.


Android also doesn't make sense for server machines, unless you've already rooted the device, in which case the restrictions that OP is having problems with don't apply.
 
Tim Moores
Saloon Keeper
Posts: 6994
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:It's literally the same thing.


Literally, yes, but in meaning, no. Tracking is what one or more apps might do to the user on a mobile device. Keeping track of devices on a network is something every company does, for multiple legitimate reasons. How those reasons might be unnatural, I have no idea.

Android also doesn't make sense for server machines, unless you've already rooted the device, in which case the restrictions that OP is having problems with don't apply.


You misunderstood. Android would not be the server - other machines on the network would be.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic