L
L
Liobon2019-05-30 15:06:09
PHP
Liobon, 2019-05-30 15:06:09

There was a question in decrypting nix, could you help?

Guys, could you help with decoding the exec fragment inside the brackets, both the first and the second. My ultimate task is to ping a gray ip every 30 seconds and display information about its status. If there are options about the implementation, I will be very grateful.

public function ping($phone_ip){
                    if ($this->myOS()){
                        if (!exec("ping -n 1 -w 1 ".$phone_ip." 2>NUL > NUL && (echo 0) || (echo 1)"))
                            return true;
                    } else {
                        if (!exec("ping -q -c1 ".$phone_ip." >/dev/null 2>&1 ; echo $?"))
                            return true;
                    }
        
                    return false;
                }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2019-05-30
@Liobon

exec("ping -n 1 -w 1 ".$phone_ip." 2>NUL > NUL && (echo 0) || (echo 1)")

Send one ICMP packet to the IP address from the variable phone_ip, wait one second for a response, return 0 if a response is received, otherwise 1.
The same, only the return code is returned ping.

V
Vasily Sorokin, 2019-05-30
@Vass

the first option for Windows, the second for Unix, the
keys say that you need to ping once and as quietly as possible, throw out all the output, except for stderr, if it exists, then print 0 otherwise 1.
Something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question