import time
import socket
REMOTE_SERVER = "one.one.one.one"
def is_connected(hostname):
try:
# DNS kontrolu
host = socket.gethostbyname(hostname)
# hosta baglan - erisilebilir mi
s = socket.create_connection((host, 80), 2)
s.close()
return True
except:
pass
return False
#timeit is_connected(REMOTE_SERVER)
#> 10 loops, best of 3: 42.2 ms per loop
while True:
if is_connected(REMOTE_SERVER)==True:
print("Internet var")
time.sleep(1)
else:
print("Internet yok")
time.sleep(1)
Hiç yorum yok:
Yorum Gönder