shodan-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/page_spec.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'shodan/page'
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Page do
6
+ before(:all) do
7
+ @host_one = Host.new('127.0.0.1','16.11.2009','SSH-2.0-OpenSSH_4.2')
8
+ @host_two = Host.new('192.168.1.1','06.11.2009','SSH-2.0-Sun_SSH_1.1','lol.cats.net')
9
+
10
+ @page = Page.new([@host_one, @host_two])
11
+ end
12
+
13
+ it "should map the Page to an Array" do
14
+ @page.map { |host| host.ip }.should == [
15
+ '127.0.0.1',
16
+ '192.168.1.1'
17
+ ]
18
+ end
19
+
20
+ it "should select hosts from the Page into another Page" do
21
+ @page.select { |host| true }.class.should == Page
22
+ end
23
+
24
+ it "should allow the enumeration of the IP addresses of hosts" do
25
+ ips = []
26
+
27
+ @page.each_ip do |ip|
28
+ ips << ip
29
+ end
30
+
31
+ ips.should == ['127.0.0.1', '192.168.1.1']
32
+ end
33
+
34
+ it "should select hosts based on their IP address" do
35
+ @page.hosts_with_ip('127.0.0.1').should == [@host_one]
36
+ end
37
+
38
+ it "should provide the IP addresses of hosts" do
39
+ @page.ips.should == ['127.0.0.1', '192.168.1.1']
40
+ end
41
+
42
+ it "should allow the enumerations of hostnames" do
43
+ names = []
44
+
45
+ @page.each_hostname { |name| names << name }
46
+
47
+ names.should == ['lol.cats.net']
48
+ end
49
+
50
+ it "should select hosts based on their hostname" do
51
+ @page.hosts_with_name('lol.cats.net').should == [@host_two]
52
+ end
53
+
54
+ it "should provide the hostnames" do
55
+ @page.hostnames.should == ['lol.cats.net']
56
+ end
57
+
58
+ it "should allow the enumeration of the dates of added hosts" do
59
+ dates = []
60
+
61
+ @page.each_date { |date| dates << date }
62
+
63
+ dates.should == [@host_one.date, @host_two.date]
64
+ end
65
+
66
+ it "should provide the dates hosts were added on" do
67
+ @page.dates.should == [@host_one.date, @host_two.date]
68
+ end
69
+
70
+ it "should allow the enumeration of responses" do
71
+ responses = []
72
+
73
+ @page.each_response { |resp| responses << resp }
74
+
75
+ responses.should == [
76
+ 'SSH-2.0-OpenSSH_4.2',
77
+ 'SSH-2.0-Sun_SSH_1.1'
78
+ ]
79
+ end
80
+
81
+ it "should select the hosts with certain responses" do
82
+ @page.responses_with('Sun').should == [@host_two]
83
+ end
84
+
85
+ it "should provide the responses of hosts" do
86
+ @page.responses.should == [
87
+ 'SSH-2.0-OpenSSH_4.2',
88
+ 'SSH-2.0-Sun_SSH_1.1'
89
+ ]
90
+ end
91
+ end
@@ -0,0 +1,95 @@
1
+ require 'shodan/query'
2
+
3
+ require 'spec_helper'
4
+ require 'has_pages_examples'
5
+ require 'page_has_hosts_examples'
6
+
7
+ describe Query do
8
+ before(:all) do
9
+ @query = Query.new(:query => 'ssh')
10
+ @page = @query.first_page
11
+ end
12
+
13
+ it_should_behave_like "has Pages"
14
+ it_should_behave_like "Page has Hosts"
15
+
16
+ describe "query expression" do
17
+ it "should support basic queries" do
18
+ q = Query.new(:query => 'ssh')
19
+
20
+ q.expression.should == 'ssh'
21
+ end
22
+
23
+ it "should support the country search operator" do
24
+ q = Query.new(
25
+ :query => 'ssh', :countries => [
26
+ Countries::Mexico,
27
+ Countries::Nicaragua
28
+ ]
29
+ )
30
+
31
+ q.expression.should == 'ssh country:MX country:NI'
32
+ end
33
+
34
+ it "should support host search operator" do
35
+ q = Query.new(
36
+ :query => 'http',
37
+ :hostnames => ['www.wired.com']
38
+ )
39
+
40
+ q.expression.should == 'http hostname:www.wired.com'
41
+ end
42
+
43
+ it "should support the net search operator" do
44
+ q = Query.new(
45
+ :query => 'ssh',
46
+ :networks => ['112.0.0.0/8']
47
+ )
48
+
49
+ q.expression.should == 'ssh net:112.0.0.0/8'
50
+ end
51
+
52
+ it "should support the port search operator" do
53
+ q = Query.new(
54
+ :query => 'login',
55
+ :ports => [21, 23]
56
+ )
57
+
58
+ q.expression.should == 'login port:21 port:23'
59
+ end
60
+ end
61
+
62
+ describe "search URL" do
63
+ before(:all) do
64
+ @uri = @query.search_url
65
+ end
66
+
67
+ it "should be a valid HTTP URI" do
68
+ @uri.class.should == URI::HTTP
69
+ end
70
+
71
+ it "should have a 'q' query-param" do
72
+ @uri.query_params['q'].should == @query.query
73
+ end
74
+ end
75
+
76
+ describe "page specific URLs" do
77
+ before(:all) do
78
+ @uri = @query.page_url(2)
79
+ end
80
+
81
+ it "should have a 'page' query-param" do
82
+ @uri.query_params['page'].should == 2
83
+ end
84
+ end
85
+
86
+ describe "queries from search URLs" do
87
+ before(:all) do
88
+ @query = Query.from_url("http://shodan.surtri.com/?q=login+port%3A21+port%3A23")
89
+ end
90
+
91
+ it "should have a query" do
92
+ @query.query.should == 'login port:21 port:23'
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,34 @@
1
+ require 'shodan/shodan'
2
+ require 'shodan/version'
3
+
4
+ require 'spec_helper'
5
+
6
+ describe "Shodan" do
7
+ it "should have a VERSION constant" do
8
+ Shodan.const_defined?('VERSION').should == true
9
+ end
10
+
11
+ describe "User-Agent support" do
12
+ it "should have a default User-Agent string" do
13
+ Shodan.user_agent.should_not be_nil
14
+ end
15
+ end
16
+
17
+ describe "Proxy support" do
18
+ it "should provide a :host key" do
19
+ Shodan.proxy.has_key?(:host).should == true
20
+ end
21
+
22
+ it "should provide a :port key" do
23
+ Shodan.proxy.has_key?(:port).should == true
24
+ end
25
+
26
+ it "should provide a :user key" do
27
+ Shodan.proxy.has_key?(:user).should == true
28
+ end
29
+
30
+ it "should provide a :password key" do
31
+ Shodan.proxy.has_key?(:password).should == true
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ gem 'rspec', '>=1.2.8'
3
+ require 'spec'
4
+
5
+ require 'shodan/version'
6
+
7
+ include Shodan
data/tasks/spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ desc "Run all specifications"
4
+ Spec::Rake::SpecTask.new(:spec) do |t|
5
+ t.libs += ['lib', 'spec']
6
+ t.spec_opts = ['--colour', '--format', 'specdoc']
7
+ end
8
+
9
+ task :test => :spec
10
+ task :default => :spec
data/tasks/yard.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'yard'
2
+
3
+ YARD::Rake::YardocTask.new do |t|
4
+ t.files = ['lib/**/*.rb']
5
+ t.options = [
6
+ '--protected',
7
+ '--files', 'History.txt',
8
+ '--title', 'SHODAN Ruby',
9
+ '--quiet'
10
+ ]
11
+ end
12
+
13
+ task :docs => :yard
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shodan-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Postmodern
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA9wb3N0
14
+ bW9kZXJuLm1vZDMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
15
+ ARkWA2NvbTAeFw0wOTA2MDMwNDU5MDNaFw0xMDA2MDMwNDU5MDNaMEYxGDAWBgNV
16
+ BAMMD3Bvc3Rtb2Rlcm4ubW9kMzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
17
+ CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
18
+ 1wvANkTDHFgVih5XLjuTwTZjgBq1lBGybXJiH6Id1lY2JOMqM5FB1DDHVvvij94i
19
+ mJabN0zkzu6VKWC70y0IwOxY7CPokr0eFdK/D0y7mCq1P8QITv76i2YqAl0eYqIt
20
+ W+IhIkANQ7E6uMZIZcdnfadC6lPAtlKkqtd9crvRbFgr6e3kyflmohbRnTEJHoRd
21
+ 7SHHsybE6DSn7oTDs6XBTNrNIn5VfZA0z01eeos/+zBm1zKJOK2+/7xtLLDuDU9G
22
+ +Rd+ltUBbvxUrMNZmDG29pnmN2xTRH+Q8HxD2AxlvM5SRpK6OeZaHV7PaCCAVZ4L
23
+ T9BFl1sfMvRlABeGEkSyuQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
24
+ sDAdBgNVHQ4EFgQUKwsd+PqEYmBvyaTyoL+uRuk+PhEwDQYJKoZIhvcNAQEFBQAD
25
+ ggEBAB4TvHsrlbcXcKg6gX5BIb9tI+zGkpzo0Z7jnxMEcNO7NGGwmzafDBI/xZYv
26
+ xkRH3/HXbGGYDOi6Q6gWt5GujSx0bOImDtYTJTH8jnzN92HzEK5WdScm1QpZKF1e
27
+ cezArMbxbSPaosxTCtG6LQTkE28lFQsmFZ5xzouugS4h5+LVJiVMmiP+l3EfkjFa
28
+ GOURU+rNEMPWo8MCWivGW7jes6BMzWHcW7DQ0scNVmIcCIgdyMmpscuAEOSeghy9
29
+ /fFs57Ey2OXBL55nDOyvN/ZQ2Vab05UH4t+GCxjAPeirzL/29FBtePT6VD44c38j
30
+ pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
31
+ -----END CERTIFICATE-----
32
+
33
+ date: 2009-12-03 00:00:00 -08:00
34
+ default_executable:
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: mechanize
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.9.3
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.8
55
+ version:
56
+ - !ruby/object:Gem::Dependency
57
+ name: yard
58
+ type: :development
59
+ version_requirement:
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.4.0
65
+ version:
66
+ - !ruby/object:Gem::Dependency
67
+ name: hoe
68
+ type: :development
69
+ version_requirement:
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.3.3
75
+ version:
76
+ description: A Ruby interface to SHODAN, a computer search engine.
77
+ email:
78
+ - postmodern.mod3@gmail.com
79
+ executables: []
80
+
81
+ extensions: []
82
+
83
+ extra_rdoc_files:
84
+ - COPYING.txt
85
+ - History.txt
86
+ - Manifest.txt
87
+ - README.txt
88
+ files:
89
+ - COPYING.txt
90
+ - History.txt
91
+ - Manifest.txt
92
+ - README.txt
93
+ - Rakefile
94
+ - lib/shodan.rb
95
+ - lib/shodan/extensions.rb
96
+ - lib/shodan/extensions/uri.rb
97
+ - lib/shodan/extensions/uri/query_params.rb
98
+ - lib/shodan/extensions/uri/http.rb
99
+ - lib/shodan/host.rb
100
+ - lib/shodan/page.rb
101
+ - lib/shodan/has_pages.rb
102
+ - lib/shodan/query.rb
103
+ - lib/shodan/shodan.rb
104
+ - lib/shodan/version.rb
105
+ - tasks/spec.rb
106
+ - tasks/yard.rb
107
+ - spec/spec_helper.rb
108
+ - spec/host_spec.rb
109
+ - spec/page_spec.rb
110
+ - spec/page_has_hosts_examples.rb
111
+ - spec/has_pages_examples.rb
112
+ - spec/query_spec.rb
113
+ - spec/shodan_spec.rb
114
+ has_rdoc: yard
115
+ homepage: http://github.com/postmodern/shodan-ruby
116
+ licenses: []
117
+
118
+ post_install_message:
119
+ rdoc_options:
120
+ - --main
121
+ - README.txt
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "0"
129
+ version:
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: "0"
135
+ version:
136
+ requirements: []
137
+
138
+ rubyforge_project: shodan-ruby
139
+ rubygems_version: 1.3.5
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: A Ruby interface to SHODAN, a computer search engine.
143
+ test_files: []
144
+
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ U�p^qp�:/+���!�e�&�Ee����YԧH� XI�^�|��lJa+J���?�����L�SA#7h/�ஜÛ}����$;Ls�xN���"�/��- Lv’�Ni���ͨ��l,��R�06�����?�:n�Ř�/��%�M�nʃ�^?���fF.)8Gy�`