如何获取域的IP地址和该域的服务器信息,以判断服务器信息是否为Apache,nginix等。?
我对如何获取IP有一个很好的想法,但由于某种原因它不会输出正确的信息:
require 'socket'
IPSocket::getaddress('http://www.prairiegraphicdesign.com/phpStuff/week2Shopping/cartAdd.php?action=add&id=4')
#<= irb(main):001:0> require 'socket'
# => true
# irb(main):002:0>IPSocket::getaddress('http://www.prairiegraphicdesign.com/phpStuff/week2Shopping/cartAdd.php?action=add&id=4')
# SocketError: getaddrinfo: No such host is known.
# from (irb):2:in `getaddress'
# from (irb):2
# from C:/Ruby22/bin/irb:11:in `<main>'
这是因为我需要将网址删除到原始网址吗?
http://www.prairiegraphicdesign.com
答案 0 :(得分:0)
这是一个网址,getaddress
不知道如何处理这些网址。它可以处理的是完全合格的域名(FQDN),如&#34; example.com&#34;。
相反,你需要打破它:
require 'uri'
uri = URI.parse('http://www.prairiegraphicdesign.com/phpStuff/week2Shopping/cartAdd.php?action=add&id=4')
uri.host
#=> "www.prairiegraphicdesign.com"
如果您愿意,可以将其解析为地址。
对于它运行的服务器软件,您需要向服务器发出HTTP请求并从响应中提取正确的标头:
require 'net/http'
res = Net::HTTP.get_response(uri)
res['server']
#=> "Microsoft-IIS/6.0"