我想到了两种方案:
1)从whois查询网站上抓取,例如http://whois.chinaz.com。
2)从whois命令行查询工具的结果中获取。Windows下的whois命令行工具 whois.exe: http://www.everbox.com/f/Mpe2uCBvbregnCPn33h8W2LLBv
这两种方案都能跨平台。
下面给出我的解决方案,优先采用1),如果查询失败再尝试2):
def whois(self, url, timeout=10): """Query whois info Compatible with windows Note: On unix please install whois first. On windows please download whois.exe from http://technet.microsoft.com/en-us/sysinternals/bb897435.aspx, then place it in Python directory e.g. C:\Python27 """ domain = common.get_domain(url) if domain: key = 'whos_%s' % domain try: text = self.cache[key] if text: return text except KeyError: pass # try http://whois.chinaz.com/ first query_url = 'http://whois.chinaz.com/%s' % domain html = self.get(query_url) if html: m = re.compile("").search(html) if m: script_url = urljoin(query_url, m.groups()[0]) text = self.get(script_url) if not text or not '@' in text: del self.cache[query_url] del self.cache[script_url] # try whois command r = subprocess.Popen(['whois', domain], stdout=subprocess.PIPE) start = time.time() while r.poll() == None: time.sleep(0.5) if time.time() - start > timeout: try: r.kill() except Exception, e: pass break if r.poll() !=1: text = r.communicate()[0] if text and '@' in text: self.cache[key] = text return text
呵呵,谢谢
VaTG790i.最好的<a href=http://www.kyfei.com>网站推广软件</a>,
非常好
....................
;ui;普i;uighur;ui;ui;个
在unix网络编程中看到了关于TCP/IP的一些内容,我感觉还是写的不够。正在下载中,一定
下载地址呢