Alexnb wrote:
Okay, I already made this post, but it kinda got lost. So anyway I need to
figure out how to test if the user is able to connect to a specific website.
Last time I got pointed to the urllib2 page, but if I do urlopen() and and
am not connected, the program stops. So I don't know if that was what you
guys wanted me to do, but I don't think so, you guys are smarter than that.
So, how can I test for connection to a website.

You can test DNS resolution by doing this:

import socket
#
# Check to make sure domain is legal and that I can resolve it to IP addr
#
try:
    ipaddr=socket.gethostbyname(domain)
except socket.gaierror:
    print "Internet connection or DNS error"

For the "connect to a specific website" portion you just have to wait until it times out to determine failure.

-Larry
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to