0

I am trying to create a utility to visualize if a set of IPs in my local network are up using python. I stumbled into a problem right away, because my plan was to use something like:

isup=os.system("ping IP")

And than depending on the value of isup I would either display that the host is online, or offline, but no matter which it is, only 0 is constantly being returned. I am using win7, and I would like to do this in python. Any help is highly appreciated!

Edit: Please stop flagging this as a duplicate, the solutions in that question are either for Linux or python 2.x.

partben
  • 25
  • 9
  • For Windows ping you can look for "TTL" in the output to indicate that the host is up. You can check this using `subprocess.check_output`. Don't look for specific error messages such as "Destination host unreachable". They get localized to the user's preferred language such as "Impossible de joindre l’hôte de destination" in French. – Eryk Sun Aug 01 '16 at 01:49
  • If your firewall blocks `ping`, no amount of programming can make your ICMP packets reach their destination. – tripleee Aug 01 '16 at 04:04
  • 1
    @tripleee, but the problem here is that Windows ping is poorly designed. It returns a success exit code if the destination is unreachable. Linux ping (from iputils) handles an unreachable destination as a failure. Thus with Windows we need to look for a real success via the presence of "TTL" in the output text. – Eryk Sun Aug 01 '16 at 04:59
  • @eryksun Thanks for clarifying! – tripleee Aug 01 '16 at 05:02

0 Answers0