Python Forum

Full Version: Ping Code Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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'
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 ?