Advertisement
ilham141201

Untitled

Jun 9th, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import requests
  2. import time
  3.  
  4. url = "http://api.myip.com/"
  5.  
  6. while True:
  7. try:
  8. response = requests.get(url)
  9.  
  10. if response.status_code == 200:
  11. data = response.json()
  12. print(data["ip"], flush=True)
  13. else:
  14. print("Error: HTTP status code", response.status_code, flush=True)
  15.  
  16. time.sleep(5) # Wait for 5 seconds before making the next request
  17.  
  18. except requests.exceptions.RequestException as e:
  19. print("An error occurred:", str(e), flush=True)
  20. time.sleep(5) # Wait for 5 seconds before making the next request
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement