1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #!/usr/local/bin/ruby require 'net/http' # Get the first argument from the command-line (the URL) url = ARGV[0] begin # Create a new HTTP connection httpCon = Net::HTTP.new( url, 80 ) # Perform a HEAD request resp, data = httpCon.head( "/", nil ) # If it succeeded (200 is success) if resp.code == "200" then # Iterate through the response hash resp.each {|key,val| # If the key is the server, print the value if key == "server" then print " The server at "+url+" is "+val+"\n" end } end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | [mtj@camus]$ ./srvrinfo.rb www.whitehouse.gov The server at www.whitehouse.gov is Apache [mtj@camus]$ ./srvrinfo.rb www.cisco.com The server at www.cisco.com is Apache/2.0 (Unix) [mtj@camus]$ ./srvrinfo.rb www.gov.ru The server at www.gov.ru is Apache/1.3.29 (Unix) [mtj@camus]$ ./srvrinfo.rb www.gov.cn [mtj@camus]$ ./srvrinfo.rb www.kantei.go.jp The server at www.kantei.go.jp is Apache [mtj@camus]$ ./srvrinfo.rb www.pmo.gov.to The server at www.pmo.gov.to is Apache/2.0.46 (Red Hat Linux) [mtj@camus]$ ./srvrinfo.rb www.mozambique.mz The server at www.mozambique.mz is Apache/1.3.27 (Unix) PHP/3.0.18 PHP/4.2.3 [mtj@camus]$ ./srvrinfo.rb www.cisco.com The server at www.cisco.com is Apache/1.0 (Unix) [mtj@camus]$ ./srvrinfo.rb www.mit.edu The server at www.mit.edu is MIT Web Server Apache/1.3.26 Mark/1.5 (Unix) mod_ssl/2.8.9 OpenSSL/0.9.7c [mtj@camus]$ ./srvrinfo.rb www.stanford.edu The server at www.stanford.edu is Apache/2.0.54 (Debian GNU/Linux) mod_fastcgi/2.4.2 mod_ssl/2.0.54 OpenSSL/0.9.7e WebAuth/3.2.8 [mtj@camus]$ ./srvrinfo.rb www.fsmgov.org The server at www.fsmgov.org is Apache/1.3.27 (Unix) PHP/4.3.1 [mtj@camus]$ ./srvrinfo.rb www.csuchico.edu The server at www.csuchico.edu is Sun-ONE-Web-Server/6.1 [mtj@camus]$ ./srvrinfo.rb www.sun.com The server at www.sun.com is Sun Java System Web Server 6.1 [mtj@camus]$ ./srvrinfo.rb www.microsoft.com The server at www.microsoft.com is Microsoft-IIS/6.0 [mtj@camus]$ ./srvrinfo.rb www.apache.org The server at www.apache.org is Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.7g |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |