Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make an android device answer to icmp pings addressed to the broadcast address?

I would like to programatically make my device answer to broadcast pings (i.e pinging 192.178.1.255) while connected to a wifi network.

Is there a way i can do that ? Maybe a listener that will ping back, or a flag to set somewhere?

Thanks.

like image 527
Intrepidd Avatar asked Oct 24 '25 14:10

Intrepidd


2 Answers

Is there a way i can do that ?

In short: Yes. But it will take some good effort to integrate the necessary components.

The key problem is that you need to listen for ICMP network packets. Such functionality is not accessible from Java and would require either JNI code or an external program. (To my knowledge, it also requires a rooted device.)

You will need a library or program that can process network traffic, such as Jpcap (which would require some modification to work on Android). You could also install and run an instance of tcpdump in the background and parse its output.

like image 196
acj Avatar answered Oct 27 '25 03:10

acj


It's not possible for an app to send/receive ICMP Echo Requests on Android. (Maybe there is a way on rooted devices)

But if your basic goal is to implement some kind of local device discovery functionality (and your code runs on all devices), you can use UDP broad/multicast messages instead.

like image 37
forgemo Avatar answered Oct 27 '25 05:10

forgemo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!