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.
7 8 9 10 |
# File 'lib/snackhack2/phone_number.rb', line 7 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.
5 6 7 |
# File 'lib/snackhack2/phone_number.rb', line 5 def save_file @save_file end |
#site ⇒ Object
Returns the value of attribute site.
5 6 7 |
# File 'lib/snackhack2/phone_number.rb', line 5 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 33 |
# 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 "[+] Status code: #{http.code}" end if !numbers.empty? if @save_file hostname = URI.parse(@site).host Snackhack2::file_save(@site, "phone_numbers", numbers.join("\n")) end end end |
#spider ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/snackhack2/phone_number.rb', line 35 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] if !pn.nil? pn = pn.compact.select { |i| !i.to_s.nil? }.shift if !phone_numbers.include?(pn.to_s) phone_numbers << pn end end end end end if !phone_numbers.empty? Snackhack2::file_save(@site, "phonenumbers", phone_numbers.join("\n")) if @save_file end end |