I have a code in php and it shows ip adress. But it works only for once when I enter. So I want to use this code to works in every 5 second.

your ip : ; 18:05
your ip : ; 18:10

like this. Can someone help me to solve this ?


    // Pull contents from ip6.me
$file = file_get_contents('http://ip6.me/');

// Trim IP based on HTML formatting
$pos = strpos( $file, '+3' ) + 3;
$ip = substr( $file, $pos, strlen( $file ) );

// Trim IP based on HTML formatting
$pos = strpos( $ip, '</' );
$ip = substr( $ip, 0, $pos );

// Output the IP address of your box
echo "My IP address ; $ip";


If you want to run an existing script every 5 seconds, displaying its output with the current date in hours & minutes, this would do it:


while :
  printf '%s ; %s\n' "$(./myip.py)" $(date +%H:%M)
  sleep 5

Hit Control-C to end the infinite loop. Besides the infinite loop and the "wait 5 seconds between each iteration", the printf statement takes the output of the script (here I named it myip.py) and appends a semicolon and the output of date +%H:%M to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.