(ip)
使用urllib2探测IP是否可以访问，并抽取应答码
    和错误原因
使用urllib2探测IP是否可以访问，并抽取应答码
    和错误原因
使用urllib2探测IP是否可以访问，并抽取应答码 和错误原因
def curl(ip):
    '''
    使用urllib2探测IP是否可以访问，并抽取应答码
    和错误原因
    '''
    url = 'http://' + ip
    request = urllib2.Request(url=url)
    reason, other = None, 0

    try:
        rsp = urllib2.urlopen(request, timeout=CONNECT_TIMEOUT + DATA_TIMEOUT)
        reason, other = rsp.getcode(), rsp.msg
    except urllib2.HTTPError, ex:
        reason, other = ex.code, ex.msg 
    except urllib2.URLError, ex:
        reason = ex.reason
        if isinstance(reason, socket.timeout):
            reason = reason.message
        elif isinstance(reason, socket.error):
            reason = reason.strerror 
    finally:
        print reason, ip, other
        result = reason, ip, other 
        global_results.append(result)
def curl ( ip ) : url = 'http://' + ip request = urllib2 . Request ( url = url ) reason , other = None , 0 try : rsp = urllib2 . urlopen ( request , timeout = CONNECT_TIMEOUT + DATA_TIMEOUT ) reason , other = rsp . getcode ( ) , rsp . msg except urllib2 . HTTPError , ex : reason , other = ex . code , ex . msg except urllib2 . URLError , ex : reason = ex . reason if isinstance ( reason , socket . timeout ) : reason = reason . message elif isinstance ( reason , socket . error ) : reason = reason . strerror finally : print reason , ip , other result = reason , ip , other global_results . append ( result )