import subprocess
internet = False
while not internet:
try:
subprocess.check_call(["ping", "-c 1", "www.google.ru"])
print("Internet is up again!")
internet = True
except subprocess.CalledProcessError:
print("Internet is still down :(")