You get different results because they are testing different things.
Ping uses ICMP (man ping)
ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to
elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST
datagrams (pings) have an IP and ICMP header, followed by a
struct timeval and then an arbitrary number of pad bytes used to