Py学习  »  Python

当我在google python上ping端口443时,python说它关闭了[复制]

John Tobey • 6 年前 • 2401 次点击  

我正在努力学习蟒蛇。这是我写的检查互联网连接的脚本

import os
import urllib2
from time import sleep
REMOTE_SERVER = "www.google.co.uk"

def is_connected():
  try:
    # see if we can resolve the host name -- tells us if there is
    # a DNS listening
    host = socket.gethostbyname(REMOTE_SERVER)
    # connect to the host -- tells us if the host is actually
    # reachable
    s = socket.create_connection((host, 80), 2)
    return True
  except:
     pass
  return False

while(1):
   if is_connected()  == False:
     print is_connected()
   sleep(10)

问题是,即使我连接到Internet,此脚本也会返回false。我可以ping www. GoGoel.C.U.K.但是这个脚本只是返回false。有什么想法吗????

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43408
文章 [ 2 ]  |  最新文章 6 年前