title: Knowing if my server is up or down using ping. .
body: <p>Thanks to all for your time.</p>
  
  <p>I'm trying to know if several server are up or down using ping, and it works . . . but when <strong>I try convert the result into a up or down, something is wrong and always is down.</strong></p>
  
  <p>Dunno what other thing I should try, don't need anything else, just up or down and the IP.</p>
  
  <pre><code>import os
  import datetime
  import platform
  import subprocess
  import string
  
  date = datetime.datetime.now()
  day = date.day
  hour = date.hour
  
  def writedoc ():
      os.chdir ('Path')
      wresult = open ("pingresults_{}_{}.txt".format(day,hour), 'a')
      wresult.write ('{}-{}\n'.format(ips, rping))
      wresult.close ()
  
  os.chdir ('Path')
  openips = open ("ips.txt","r")
  ipfile = openips.readlines()
  
  for ips in ipfile:
      ips = ips.strip()
      print (ips)
      args = ["ping", "-n", "4", "-l", "1", "-w", "1000", ips]
      pping = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
      rping = pping.stdout
      for line in rping:
          print (line)
      if (rping.find("(100% perdidos)" != -1)):
          result = "down"
          print (result)
      else:
          result = "up"
          print (result)
      writedoc()
  </code></pre>