Here is a version 3 that takes care of wrapping the previous logic as a Class. It also exposes a RoundTripTime property instead of the entire ICMP_ECHO_REPLY structure (that is seldom needed anyway).
Remember, this is done with simple API calls. Thus you have none of the issues of the slow, clunky, heavyweight, and erratically available WMI Service - which was designed to support occasional admin scripting and not application logic. This works even where WMI doesn't exist at all, as well as where the Service has been disabled for security reasons.