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

烈酒焚心 提交于 2019-12-08 01:26:43

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13219522/is-there-a-way-to-make-an-android-device-answer-to-icmp-pings-addressed-to-the-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!