Check if the internet works – Python


Just check a google server

74.125.228.100 is one of the IP-addresses for google.com. Change http://74.125.228.100 to whatever site can be expected to respond quickly.
Using a numerical IP-address avoids a DNS lookup, which may block the urllib2.urlopen call for more than a second.

Thanks to @rzetterberg for pointing this out.

By specifying the timeout=1 parameter, the call to urlopen will not take much longer than 1 second even if the internet is not “on”.

Good Luck

About

“I am not what I ought to be, I am not what I want to be, I am not what I hope to be in another world; but still I am not what I once used to be, and by the grace of God I am what I am”

Tagged with: , , ,
Posted in Programming

Leave a comment

Member of The Internet Defense League

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 516 other subscribers
Follow NextDime Networks on WordPress.com
My Community
Follow me on Twitter
Top Rated Posts
My Gravatar
nextdime

nextdime

“I am not what I ought to be, I am not what I want to be, I am not what I hope to be in another world; but still I am not what I once used to be, and by the grace of God I am what I am”

Verified Services

View Full Profile →