Class: Shodan::Host
- Inherits:
-
Object
- Object
- Shodan::Host
- Defined in:
- lib/shodan/host.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
The date the host was added.
-
#hostname ⇒ Object
readonly
The host-name of the host.
-
#http_body ⇒ Object
readonly
The body of the HTTP response.
-
#http_code ⇒ Object
readonly
The HTTP status code in the response.
-
#http_headers ⇒ Object
readonly
The HTTP headers included in the response.
-
#http_status ⇒ Object
readonly
The HTTP status string in the response.
-
#http_version ⇒ Object
readonly
The HTTP version supported by the host.
-
#ip ⇒ Object
readonly
The IP of the host.
-
#response ⇒ Object
readonly
The response returned by the host.
Instance Method Summary collapse
-
#initialize(ip, date, response, hostname = nil) ⇒ Host
constructor
Creates a new Host object.
-
#server_name ⇒ String
The server software the host runs.
-
#server_version ⇒ String
The server software version.
Constructor Details
#initialize(ip, date, response, hostname = nil) ⇒ Host
Creates a new Host object.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/shodan/host.rb', line 66 def initialize(ip,date,response,hostname=nil) @ip = ip @date = Date.parse(date) @response = response @hostname = hostname @http_version = nil @http_code = nil @http_status = nil @http_headers = {} @http_body = nil if response =~ /^HTTP\/?/ lines = response.split(/[\r\n]/) match = lines.first.split(/\s+/,3) if match[0].include?('/') @http_version = match[0].split('/').last end if match[1] @http_code = match[1].to_i end @http_status = match[2] @http_body = '' lines[1..-1].each_with_index do |line,index| if line.empty? @http_body = lines[(index+2)..-1].join("\n") break end name, value = line.chomp.split(/:\s+/,2) @http_headers[name] = value end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object (protected)
Provides transparent access to the values in headers
.
135 136 137 138 139 140 141 142 143 |
# File 'lib/shodan/host.rb', line 135 def method_missing(sym,*args,&block) if (args.empty? && block.nil?) name = sym.id2name.gsub(/_/,'-').capitalize return @http_headers[name] if @http_headers.key?(name) end return super(sym,*args,&block) end |
Instance Attribute Details
#date ⇒ Object (readonly)
The date the host was added
28 29 30 |
# File 'lib/shodan/host.rb', line 28 def date @date end |
#hostname ⇒ Object (readonly)
The host-name of the host
31 32 33 |
# File 'lib/shodan/host.rb', line 31 def hostname @hostname end |
#http_body ⇒ Object (readonly)
The body of the HTTP response
49 50 51 |
# File 'lib/shodan/host.rb', line 49 def http_body @http_body end |
#http_code ⇒ Object (readonly)
The HTTP status code in the response
40 41 42 |
# File 'lib/shodan/host.rb', line 40 def http_code @http_code end |
#http_headers ⇒ Object (readonly)
The HTTP headers included in the response
46 47 48 |
# File 'lib/shodan/host.rb', line 46 def http_headers @http_headers end |
#http_status ⇒ Object (readonly)
The HTTP status string in the response
43 44 45 |
# File 'lib/shodan/host.rb', line 43 def http_status @http_status end |
#http_version ⇒ Object (readonly)
The HTTP version supported by the host
37 38 39 |
# File 'lib/shodan/host.rb', line 37 def http_version @http_version end |
#ip ⇒ Object (readonly)
The IP of the host
25 26 27 |
# File 'lib/shodan/host.rb', line 25 def ip @ip end |
#response ⇒ Object (readonly)
The response returned by the host
34 35 36 |
# File 'lib/shodan/host.rb', line 34 def response @response end |
Instance Method Details
#server_name ⇒ String
The server software the host runs.
112 113 114 115 116 |
# File 'lib/shodan/host.rb', line 112 def server_name if (server = @http_headers['Server']) return server.split('/',2).first end end |
#server_version ⇒ String
The server software version.
124 125 126 127 128 |
# File 'lib/shodan/host.rb', line 124 def server_version if (server = @http_headers['Server']) return server.split('/',2).last end end |