Oct-12-2016, 04:27 PM
This is not a foolproof way to test if internet is active or not, but I find that it works in at least 90% of the cases.
If someone has a better (as in works better) method, please post here.
If someone has a better (as in works better) method, please post here.
import socket class HasInternet: def __init__(self): self.ipaddress = socket.gethostbyname(socket.gethostname()) self.isactive = self.ipaddress != '127.0.0.1' if __name__ == '__main__': conn = HasInternet() if conn.isactive: print('Internet is active') else: print('Internet is inactive')