• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

The local ARP table on Android(/proc/net/arp) only has the router logged in it... why?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't really a Java specific question... it involves Android. I thought I would ask it here since there seem to be some interesting people on this site.



This reads the local ARP table on Android, which is cool. The problem is: the table only has one device in it... the router. Why doesn't it list all the other devices on the network? There are clearly more devices on the network other than the router.

One theory I've had is it only lists the devices that have been accessed by my Android device.(I don't know much about computer networking so this is all I could come up with)

Does anyone know why it only shows the router in the ARP table and nothing else?
 
Saloon Keeper
Posts: 15253
349
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel, welcome to CodeRanch!

I don't know about your question, I don't have enough experience with ARP to know what's going on. Maybe the router doesn't want to give up the other devices? I'm not sure.

I can however tell you that you're not using the correct idiom to read files. Since you're not closing the reader, you may run out of file system handles as you query the ARP table. Here's how the code should read:

Or if you're interested in individual lines, and the file is not too big:

Or if you have big files and you're on Java 8:
 
Ranch Hand
Posts: 165
12
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IIRC the ARP table is just a cache of recently discovered IP-MAC mappings. After a while the table is trimmed and older entries removed. Its purpose is merely to avoid continually having to request the same mapping info over and over by caching it here for a while.
 
Daniel Crawford
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steffe Wilson wrote:IIRC the ARP table is just a cache of recently discovered IP-MAC mappings. After a while the table is trimmed and older entries removed. Its purpose is merely to avoid continually having to request the same mapping info over and over by caching it here for a while.



Ah... that's a bit of a downer.

Would you know of any other ways to discover the devices on your network?

I've tried:

but it's very inefficient. It takes way too long to go through all 255. Any help is appreciated!
 
Stephan van Hulst
Saloon Keeper
Posts: 15253
349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way is probably to do this using native Linux commands, or by invoking a process that can do this. Maybe you can install something like nmap on Android?

Why do you want to see all hosts in the network?
 
Daniel Crawford
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:The best way is probably to do this using native Linux commands, or by invoking a process that can do this. Maybe you can install something like nmap on Android?

Why do you want to see all hosts in the network?



I'm working on a network scanning tool similar to Fing.

I've decompiled the APK files for some similar apps but I'm terrible at understanding the code. I managed to understand they were pulling something from the /proc/net/arp file. I need to study their apps some more... but I was hoping someone could push me in the right direction.

Wouldn't I need root access for the app to access linux commands?
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now, the scan is sequential. You can reduce the total time by probing from multiple background threads - a single or a couple of IP addresses per thread.

As Stephen says, a possibly faster way is running "/system/bin/ping -c1 <ip>", again from multiple threads. The -c1 means send just 1 packet, to reduce the time.
Run it using java.lang.ProcessBuilder. /system/bin/ping is part of stock android, and you don't need root to run it.

If you're really adventurous, I think you can possibly extract bits of relevant code from ping.c or arping.c (both are GPL open source), compile them as an NDK project into its own native library,
bundle that library into your APK, and call a ping/arping function from your app via JNI.
It's rather complex, but it may reduce the overhead of android having to launch many ping processes and reduce total time. I have not tried this, it's just a (remote and possibly high effort) possibility.
 
Daniel Crawford
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! I can't test any of this now but I will ASAP.

I will definitely try the more adventrous approach once I get the simpler approach working. That would be amazing if I could get something like that working.
I'm really thankful for the posts! You guys really opened my mind to some possibilities on Android.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic