Class: Snackhack2::PhoneNumber
- Inherits:
-
Object
- Object
- Snackhack2::PhoneNumber
- Defined in:
- lib/snackhack2/phone_number.rb
Instance Attribute Summary collapse
-
#save_file ⇒ Object
Returns the value of attribute save_file.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(save_file: true) ⇒ PhoneNumber
constructor
A new instance of PhoneNumber.
- #run ⇒ Object
- #spider ⇒ Object
Constructor Details
#initialize(save_file: true) ⇒ PhoneNumber
Returns a new instance of PhoneNumber.
9 10 11 12 |
# File 'lib/snackhack2/phone_number.rb', line 9 def initialize(save_file: true) @site = site @save_file = save_file end |
Instance Attribute Details
#save_file ⇒ Object
Returns the value of attribute save_file.
7 8 9 |
# File 'lib/snackhack2/phone_number.rb', line 7 def save_file @save_file end |
#site ⇒ Object
Returns the value of attribute site.
7 8 9 |
# File 'lib/snackhack2/phone_number.rb', line 7 def site @site end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/snackhack2/phone_number.rb', line 16 def run numbers = [] http = Snackhack2.get(@site) if http.code == 200 regex = http.body phone = regex.scan(/((\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4})/) out = phone.map { |n| n[0] }.compact numbers << out else puts "\n\n[+] Status code: #{http.code}" end return if numbers.empty? return unless @save_file URI.parse(@site).host Snackhack2.file_save(@site, 'phone_numbers', numbers.join("\n")) end |
#spider ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/snackhack2/phone_number.rb', line 34 def spider phone_numbers = [] Spidr.start_at(@site, max_depth: 4) do |agent| agent.every_page do |page| body = page.to_s if body.scan(/((\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4})/) pn = body.scan(/((\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4})/)[0] unless pn.nil? pn = pn.compact.reject { |i| i.to_s.nil? }.shift phone_numbers << pn unless phone_numbers.include?(pn.to_s) end end end end return if phone_numbers.empty? Snackhack2.file_save(@site, 'phonenumbers', phone_numbers.join("\n")) if @save_file end |