socialinvestigator 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b05afd1645671efac34a27455b466ae120bd0796
4
- data.tar.gz: d8e96eb8befbf7fb8124b3cba94d711e18157f52
3
+ metadata.gz: 13d1c86f7088d598bb4c4b81b1ce4a5d1c9344ee
4
+ data.tar.gz: 2c6385e6b65ea955f39647849c072d4212d40c1d
5
5
  SHA512:
6
- metadata.gz: 9481ba394a0fdc6380c48a0d2f1eeaeda14b1abedb993f83d95a423acd5be718bbedbd272e3b95e0ce6074b409fa8580550f9df1955f05f9f3dd6aec586d2661
7
- data.tar.gz: 3f94308447f5a9bb6a28bd013066637c2cb588c84db01f2ff840511cd6acf9a2890a4fbfc149f037d9026d4c9643dcd359c7f9593504a01d8c2b5b5d5aa24596
6
+ metadata.gz: d1540385a853c75ce6b0d47146412048022f2f0ba1175f90415168ea970d7257d4b312a38cd04138c2f6709da4de97b9c9e7e58028d2d7a3a3179a6f1b6f9872
7
+ data.tar.gz: c311cba9fb6267e86b5218fc699734f533edeff2394ff32cb185a0e102be3d873f6db740a604a62f3ecf9b0c101c8802053d4cbb178854edaf7912eb3db98459
data/README.md CHANGED
@@ -15,6 +15,7 @@ Then you can run the command 'socialinvestigator' to begin using it.
15
15
  ## Usage
16
16
 
17
17
  Full help
18
+
18
19
  $ socialinvestigator help
19
20
 
20
21
  ## Hacker News Search
@@ -4,8 +4,17 @@ module Socialinvestigator
4
4
  module CLI
5
5
  class Net < Thor
6
6
  desc "page_info URL", "Looks at a page to see what social links it finds"
7
+ options [:noreverse, :debug]
8
+ long_desc <<-PAGE_INFO
9
+ page_info URL
10
+
11
+ Looks at a page to see what social links it finds
12
+
13
+ --noreverse skips the reverse ip lookup and associate whois call
14
+ --debug prints out every fact that is discovered
15
+ PAGE_INFO
7
16
  def page_info( url )
8
- knowledge = client.get_knowledge( url )
17
+ knowledge = client.get_knowledge( url, options[:noreverse], options[:debug] )
9
18
  knowledge.print
10
19
  end
11
20
 
@@ -3,118 +3,139 @@ require 'httparty'
3
3
  require 'nokogiri'
4
4
  require 'dnsruby'
5
5
  require 'whois'
6
+ require 'whois/record/parser/blank'
7
+ require 'whois/record/contact'
6
8
 
7
9
  module Socialinvestigator
8
10
  module Client
9
- class PageKnowledge
10
- DEBUG = false
11
- TEMPLATE = "%20s: %s\n"
12
-
13
- def initialize; @knowledge = {} end
11
+ module Net
12
+ class PageKnowledge
13
+ @debug = false
14
+ TEMPLATE = "%20s: %s\n"
15
+
16
+ def initialize( debug = false )
17
+ @debug = debug
18
+ @knowledge = {}
19
+ end
14
20
 
15
- def remember( key, value )
16
- return if value.nil?
17
- p key, value if DEBUG
21
+ def remember( key, value )
22
+ return if value.nil?
23
+ p key, value if @debug
18
24
 
19
- @knowledge[key] = value
20
- end
25
+ @knowledge[key] = value
26
+ end
21
27
 
22
- def another( key, value )
23
- return if value.nil?
24
- p key, value if DEBUG
28
+ def another( key, value )
29
+ return if value.nil?
30
+ p key, value if @debug
25
31
 
26
- @knowledge[key] ||= []
27
- @knowledge[key] << value
28
- @knowledge[key] = @knowledge[key].uniq
29
- end
32
+ @knowledge[key] ||= []
33
+ @knowledge[key] << value
34
+ @knowledge[key] = @knowledge[key].uniq
35
+ end
30
36
 
31
- def print
32
- p :domain
33
- p :created_on
34
- p :expires_on
35
- p :updated_on
36
- p :registrar_name
37
- p :registrar_url
38
- p :registrant_contact
39
- p :admin_contact
40
- p :technical_contact
41
- p :emails
42
- p :title, title
43
- p :description, description
44
- p :twitter_author, twitter_author
45
- p :twitter_ids
46
- p :image, image
47
- p :responsive
48
- p :rss_feed
49
- p :atom_feed
50
-
51
- p :twitter_links
52
- p :linkedin_links
53
- p :instagram_links
54
- p :facebook_links
55
- p :googleplus_links
56
- p :github_links
57
- p :technologies
58
- end
37
+ def print
38
+ p :domain
39
+ p :created_on
40
+ p :expires_on
41
+ p :updated_on
42
+ p :registrar_name
43
+ p :registrar_url
44
+ p :registrant_contact
45
+ p :admin_contact
46
+ p :technical_contact
47
+
48
+ p :server_name
49
+ p :server_country
50
+ p :server_location
51
+ p :server_latitude
52
+ p :server_longitude
53
+ p :server_ip_owner
54
+
55
+ p :emails
56
+ p :title, title
57
+ p :description, description
58
+ p :twitter_author, twitter_author
59
+ p :twitter_ids
60
+ p :image, image
61
+ p :responsive
62
+ p :rss_feed
63
+ p :atom_feed
64
+
65
+ p :twitter_links
66
+ p :linkedin_links
67
+ p :instagram_links
68
+ p :facebook_links
69
+ p :googleplus_links
70
+ p :github_links
71
+ p :technologies
72
+ end
59
73
 
60
- def p( key, val = nil )
61
- val = @knowledge[key] if val.nil?
62
- if val.is_a?( Array )
63
- printf TEMPLATE, key, val.join( ", ") if val.size > 0
64
- elsif val.is_a?( Whois::Record::Contact )
65
- printf TEMPLATE, key, ""
66
- [:name, :organization, :address, :city, :zip, :state, :country, :country_code, :phone, :fax, :email, :url, :created_on, :updated_on].each do |key|
67
- out = val.send( key )
68
- printf "%25s: %s\n", key, out if out && out != ""
74
+ def p( key, val = nil )
75
+ val = @knowledge[key] if val.nil?
76
+ if val.is_a?( Array )
77
+ printf TEMPLATE, key, val.join( ", ") if val.size > 0
78
+ elsif val.is_a?( Whois::Record::Contact )
79
+ printf TEMPLATE, key, ""
80
+ [:name, :organization, :address, :city, :zip, :state, :country, :country_code, :phone, :fax, :email, :url, :created_on, :updated_on].each do |key|
81
+ out = val.send( key )
82
+ printf "%25s: %s\n", key, out if out && out != ""
83
+ end
84
+ else
85
+ printf TEMPLATE, key, val if val
69
86
  end
70
- else
71
- printf TEMPLATE, key, val if val
72
87
  end
73
- end
74
88
 
75
- def title
76
- @knowledge[:twitter_title] || @knowledge[:og_title] || @knowledge[:page_title]
77
- end
89
+ def title
90
+ @knowledge[:twitter_title] || @knowledge[:og_title] || @knowledge[:page_title]
91
+ end
78
92
 
79
- def twitter_author
80
- @knowledge[:twitter_creator] || @knowledge[:twitter_by] || @knowledge[:twitter_site_author] || (@knowledge[:twitter_ids] || []).first
81
- end
93
+ def twitter_author
94
+ @knowledge[:twitter_creator] || @knowledge[:twitter_by] || @knowledge[:twitter_site_author] || (@knowledge[:twitter_ids] || []).first
95
+ end
82
96
 
83
- def description
84
- @knowledge[:twitter_description] || @knowledge[:og_description] || @knowledge[:description]
85
- end
97
+ def description
98
+ @knowledge[:twitter_description] || @knowledge[:og_description] || @knowledge[:description]
99
+ end
86
100
 
87
- def image
88
- @knowledge[:twitter_image] || @knowledge[:og_image]
101
+ def image
102
+ @knowledge[:twitter_image] || @knowledge[:og_image]
103
+ end
89
104
  end
90
- end
91
105
 
92
- class NetClient
93
- # Look up the domain
94
-
95
- def find_domain( hostname )
96
- # puts "Looking for SOA of #{hostname}"
97
- dns = Dnsruby::Resolver.new
98
- soa = dns.query( hostname, "SOA" ).answer.select do |rr|
99
- rr.is_a? Dnsruby::RR::IN::SOA
106
+ class DNS
107
+ def initialize
108
+ @resolv = Dnsruby::Resolver.new
100
109
  end
101
110
 
102
- return hostname if soa.length > 0
111
+ def find_domain( hostname )
112
+ # puts "Looking for SOA of #{hostname}"
113
+ soa = @resolv.query( hostname, "SOA" ).answer.select do |rr|
114
+ rr.is_a? Dnsruby::RR::IN::SOA
115
+ end
116
+
117
+ return hostname if soa.length > 0
103
118
 
104
- parts = hostname.split( /\./ )
105
- return nil if parts.length <= 2
119
+ parts = hostname.split( /\./ )
120
+ return nil if parts.length <= 2
106
121
 
107
- find_domain( parts.slice(1,100).join( "." ) )
122
+ find_domain( parts.slice(1,100).join( "." ) )
123
+ end
108
124
  end
125
+ end
126
+
127
+ class NetClient
128
+ # Look up the domain
109
129
 
110
- def get_knowledge( url )
111
- data = PageKnowledge.new
130
+ def get_knowledge( url, noreverse = false, debug = false )
131
+ data = Socialinvestigator::Client::Net::PageKnowledge.new( debug )
132
+ dns = Socialinvestigator::Client::Net::DNS.new
112
133
 
113
134
  uri = URI( url )
114
135
 
115
136
  data.remember( :hostname, uri.hostname )
116
137
 
117
- domain = find_domain(uri.hostname)
138
+ domain = dns.find_domain(uri.hostname)
118
139
 
119
140
  data.remember( :domain, domain )
120
141
 
@@ -143,16 +164,7 @@ module Socialinvestigator
143
164
  data.remember( :technical_contact, c )
144
165
  end
145
166
  end
146
- # [
147
- # :name,:organization,:address,:city,
148
- # :zip,:state,:country,:country_code,
149
- # :phone,:fax,:email,:url].each do |k|
150
- # val = c.send(k)
151
- # printf "%15s : %s\n", k.to_s, val if !val.nil?
152
- # end
153
- # end
154
-
155
- require 'whois/record/parser/blank'
167
+
156
168
  whois.parts.each do |p|
157
169
  if Whois::Record::Parser.parser_for(p).is_a? Whois::Record::Parser::Blank
158
170
  puts "Couldn't find a parser for #{p.host}:"
@@ -161,7 +173,33 @@ module Socialinvestigator
161
173
  end
162
174
 
163
175
 
176
+ if !noreverse
177
+ ip_address = Dnsruby::Resolv.getaddress uri.host
178
+
179
+ if ip_address
180
+ data.remember :ip_address, ip_address
181
+ begin
182
+ data.remember :server_name, Dnsruby::Resolv.getname( ip_address )
183
+ rescue Dnsruby::NXDomain
184
+ # Couldn't do the reverse lookup
185
+ end
186
+
187
+ location_info = HTTParty.get('http://freegeoip.net/json/' + ip_address)
188
+
189
+ data.remember :server_country, location_info['country_name']
190
+ data.remember :server_location, [location_info['city'], location_info['region_name']].collect { |x| (x != nil && x != "") ? x : nil }.select { |x| x }.join( ", ")
191
+ data.remember :server_latitude, location_info['latitude']
192
+ data.remember :server_longitude, location_info['longitude']
164
193
 
194
+ ip_whois = Whois.lookup ip_address
195
+
196
+ ip_whois.to_s.each_line.select { |x| x=~/Organization/ }.each do |org|
197
+ if org =~ /Organization:\s*(.*)\n/
198
+ data.another :server_ip_owner, $1
199
+ end
200
+ end
201
+ end
202
+ end
165
203
 
166
204
  # Load up the response
167
205
 
@@ -4,10 +4,13 @@ require 'nokogiri'
4
4
  require 'dnsruby'
5
5
  require 'whois'
6
6
 
7
+ require 'whois/record/parser/blank'
8
+ require 'whois/record/contact'
9
+
7
10
  url = ARGV[0] || "http://www.fastcolabs.com/3038014/product-bootcamp-week-six-worth-it"
8
11
 
9
12
  class PageKnowledge
10
- DEBUG = false
13
+ DEBUG = true
11
14
  TEMPLATE = "%20s: %s\n"
12
15
 
13
16
  def initialize; @knowledge = {} end
@@ -38,6 +41,13 @@ class PageKnowledge
38
41
  p :registrant_contact
39
42
  p :admin_contact
40
43
  p :technical_contact
44
+ p :server_name
45
+ p :server_country
46
+ p :server_location
47
+ p :server_latitude
48
+ p :server_longitude
49
+ p :server_ip_owner
50
+
41
51
  p :emails
42
52
  p :title, title
43
53
  p :description, description
@@ -153,7 +163,6 @@ end
153
163
  # end
154
164
  # end
155
165
 
156
- require 'whois/record/parser/blank'
157
166
  whois.parts.each do |p|
158
167
  if Whois::Record::Parser.parser_for(p).is_a? Whois::Record::Parser::Blank
159
168
  puts "Couldn't find a parser for #{p.host}:"
@@ -161,7 +170,33 @@ whois.parts.each do |p|
161
170
  end
162
171
  end
163
172
 
173
+ # Lookup IP Address info
174
+
175
+ ip_address = Dnsruby::Resolv.getaddress uri.host
176
+
177
+ if ip_address
178
+ data.remember :ip_address, ip_address
179
+ begin
180
+ data.remember :server_name, Dnsruby::Resolv.getname( ip_address )
181
+ rescue Dnsruby::NXDomain
182
+ # Couldn't do the reverse lookup
183
+ end
164
184
 
185
+ location_info = HTTParty.get('http://freegeoip.net/json/' + ip_address)
186
+
187
+ data.remember :server_country, location_info['country']
188
+ data.remember :server_location, [location_info['city'], location_info['region_name']].select { |x| x }.join( ", ")
189
+ data.remember :server_latitude, location_info['latitude']
190
+ data.remember :server_longitude, location_info['longitude']
191
+
192
+ ip_whois = Whois.lookup ip_address
193
+
194
+ ip_whois.to_s.each_line.select { |x| x=~/Organization/ }.each do |org|
195
+ if org =~ /Organization:\s*(.*)\n/
196
+ data.another :server_ip_owner, $1
197
+ end
198
+ end
199
+ end
165
200
 
166
201
 
167
202
  # Load up the response
@@ -1,3 +1,3 @@
1
1
  module Socialinvestigator
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialinvestigator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Schenk
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.2.2
171
+ rubygems_version: 2.2.1
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Simple command line tool to look at urls.