<div class="gmail_quote">Hi All,<div><br></div><div>I am using the following snippet to check the availability of an IP address. If that IP addr is found free than it can be used later on for further operations.</div><div>
<div>Python ver 3.2</div>
<div>Windows OS</div></div><div><br></div><div>{{{</div><div><div>pingret = subprocess.Popen('ping {0}'.format(IPaddr), shell=True,universal_newlines=True, \</div><div> stdout=subprocess.PIPE, stderr=subprocess.STDOUT)</div>
<div>status = pingret.wait()</div><div>if status == 0:</div><div> print("WARN The IP given in the input is not free")</div><div>.....</div><div>.....</div><div>}}}</div><div><br></div><div>Normal ping operation on windows cmd prompt can give 3 outputs.</div>
<div>1) "destination host unreachable</div><div>2) "request timed out"</div><div>3) "Reply from <a href="http://192.168.1.1" target="_blank">192.168.1.1</a>: bytes=32 time=3ms TTL=64"</div><div><br>
</div><div>Now, </div>
<div>I was expecting the "status" in above snippet to hold '0' only in case of no. 3)</div><div>But even when we have case 1), 'status' is holding '0'. </div><div>i.e. The exit status of ping is 0, even when destination host is unreachable.!</div>
<div><br></div><div>How do I make my snippet to work as desired. i.e even if destination host is unreachable, 'status' should hold '1' and hold '0' only when it gets reply from that ip address.??</div>
<div><br></div><div><br></div><div>Thanks,</div><div><br></div>Nikunj<span class="HOEnZb"><font color="#888888"><br><br><div><br></div><div><div dir="ltr"><div dir="ltr">--</div><div dir="ltr"><b style><i><span style="font-size:18pt;font-family:'Wingdings 3';color:rgb(192,0,0)">7</span></i></b><span style="font-size:10pt;color:rgb(31,73,125)">Switch off as you go </span><span style="font-size:18pt;color:rgb(23,54,93)">|</span><b style><span style="font-size:18pt;font-family:Webdings;color:rgb(118,146,60)">q</span></b><span style="font-size:10pt;color:rgb(31,73,125)">Recycle always</span><span style="font-size:18pt;color:rgb(23,54,93)"> | </span><span style="font-size:18pt;font-family:Webdings;color:rgb(0,176,80)">P </span><span style="font-size:10pt;color:rgb(31,73,125)">Save Paper - Save Trees</span><span style="font-size:18pt;color:rgb(23,54,93)"> |</span><span style="font-size:18pt;color:rgb(89,89,89)"> </span><span style="font-size:10pt;color:rgb(31,73,125)">Go Green </span></div>
</div></div><br>
</font></span></div>
</div><br>