Python Forum
Use of classes or functions discussion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of classes or functions discussion
#1
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.

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')
Reply


Messages In This Thread
Use of classes or functions discussion - by Larz60+ - Oct-12-2016, 04:27 PM
RE: Test internet connection - by micseydel - Oct-12-2016, 05:51 PM
RE: Test internet connection - by Larz60+ - Oct-12-2016, 08:37 PM
RE: Test internet connection - by micseydel - Oct-12-2016, 08:52 PM
RE: Test internet connection - by Larz60+ - Oct-12-2016, 11:13 PM
RE: Test internet connection - by micseydel - Oct-12-2016, 11:19 PM
RE: Test internet connection - by Larz60+ - Oct-12-2016, 11:28 PM
RE: Test internet connection - by micseydel - Oct-12-2016, 11:34 PM
RE: Test internet connection - by wavic - Oct-12-2016, 11:38 PM
RE: Test internet connection - by Mekire - Oct-13-2016, 12:28 AM
RE: Test internet connection - by Larz60+ - Oct-12-2016, 11:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  discussion: API proposal for a better numpy jimy_byerley 0 1,541 Jul-19-2020, 08:56 PM
Last Post: jimy_byerley
  ok to post functions/classes/modules? Skaperen 2 3,059 Jul-03-2018, 12:22 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020