title: Ping command - Check returned value
body: <p>How can I evaluate the return of <code>ping</code> command used on <code>subprocess.call()</code>, by having a value of True or False like in the last &quot;if&quot; statement ? <br>
  Here is the code: <br></p>
  <pre class="lang-py prettyprint-override"><code>import subprocess
  from openpyxl import load_workbook
  from openpyxl import worksheet
  _list_test = []
  
  def ping_rng():
      wb = load_workbook(filename=&quot;IP_gav.xlsx&quot;)
      ws = wb[&quot;172.16.7.X&quot;]
      i = 0
  
      for IP_ in range(2,258):
  
          # Get correct cell value
          cell_ = ws.cell(row=IP_, column=1).value
          _list_test.append(cell_)
  
          # Construct and execute &quot;ping&quot; command
          cmd_param = &quot;-n&quot;
          command = ['ping', cmd_param, '1', str(_list_test[i])]
          response = subprocess.call(command)
  
          print(response)   # Just to check the value
          
          # Check the &quot;response&quot;
          if response == True:
              print(&quot;Is up.&quot;)
          elif response == False:
              print(&quot;Is down.&quot;)
          else: print(&quot;Nothing Good&quot;)
  
          i = i + 1
  
  ping_rng()
  </code></pre>
  <p>The code is working as it should, by iterating on a range of IP addresses (which it get from a XLSX file) and by pinging the single IP address like so:</p>
  <pre><code>ping 172.16.7.0 -n 1
  </code></pre>
  <p>As a further attempt, I've found different posts about verifying if <strong>subprocess.check_output()</strong> is True or False, but this didn't worked for me since it returns the string of ping command in &quot;cmd style&quot;, and that is why I've opted for subprocess.call() which returns the state of the command. <br>
  <strong>Tests:</strong> <br>
  In the code above, I printed the value of &quot;response&quot; variable by using the 2 different methods: <br></p>
  <ul>
  <li>With <strong>subprocess.call()</strong> the return is '0' in any cases (so return <strong>False</strong> in the last &quot;if&quot; statement)<br>
  or</li>
  <li>With <strong>subprocess.check_output()</strong> the return is the ping command itself in &quot;cmd style&quot; (return <strong>&quot;Nothing Good&quot;</strong> in the last &quot;if&quot; statement) <br><br></li>
  </ul>