how to icmp ping on android

前端 未结 4 961
执念已碎
执念已碎 2020-12-08 08:11

I need to do a icmp ping to a host from my android device. I need to measure the round trip time. I am proficient with android and java, just dont know what library to use.

4条回答
  •  天命终不由人
    2020-12-08 08:56

    From the socket(2) man page ping access in the device is restricted by the content of the /proc/sys/net/ipv4/ping_group_range file

    $ cat /proc/sys/net/ipv4/ping_group_range

    It is "1 0" by default, meaning that nobody (not even root) may create ping sockets. Setting it to "100 100" would grant permissions to the single group (to either make /sbin/ping g+s and owned by this group or to grant permissions to the "netadmins" group), "0 4294967295" would enable it for the world, "100 4294967295" would enable it for the users, but not daemons.

    so any devices with other than "0 4294967295" cant access from an android java application

    In emulator you can test this be resetting

    sysctl -w net.ipv4.ping_group_range="0 0" // to some range

提交回复
热议问题