Python Forum
Ping Code Problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Ping Code Problem (/thread-12625.html)



Ping Code Problem - MTom5 - Sep-04-2018

I have the following block of code which i use to Ping multiple addresses

        AN_Sel_State = var4.get()
        if (AN_Sel_State == 1):
            if(s.call(["ping", Output_IP_Address_AN])==0):
                    print("'Ping' Sucessful")
                    IPT_Display_AN = Label(IPT, text=(Output_IP_Address_AN, "Ok"),fg='green', anchor=W)
                    IPT_Display_AN_Window = canvas_IPT.create_window(150, 235, anchor = 'sw', window = IPT_Display_AN)
            else:
                    print("'Ping' NOT Sucessful")
                    IPT_Display_AN = Label(IPT, text=(Output_IP_Address_AN, "Failed"),fg='red', anchor=W)
                    IPT_Display_AN_Window = canvas_IPT.create_window(150, 235, anchor = 'sw', window = IPT_Display_AN)
This works as expected in instances were packet data is received (Succesful) and also works when 'Request timed out' (Not Succesful) however when 'Host Unreachable' it returns the result is successful which is wrong.

I cant seem to work out what my mistake is the return should be ==1 in both instances of 'Request timed out' and 'Host Unreachable'


RE: Ping Code Problem - MTom5 - Sep-04-2018

Done some more research on this and i am lead to believe that "Host Unreachable" returns as ==0 even though the ping wasn't actually successful (Still dont really understand why this is ?)

If this is the case how do i exclude "Host Unreachable" from displaying successful when it has the same exit status ?