Class: Snackhack2::PhoneNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/snackhack2/phone_number.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject

Returns the value of attribute save_file.



7
8
9
# File 'lib/snackhack2/phone_number.rb', line 7

def save_file
  @save_file
end

#siteObject

Returns the value of attribute site.



7
8
9
# File 'lib/snackhack2/phone_number.rb', line 7

def site
  @site
end

Instance Method Details

#runObject



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

#spiderObject



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