Class: Snackhack2::IpLookup

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

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ IpLookup

Returns a new instance of IpLookup.



5
6
7
# File 'lib/snackhack2/iplookup.rb', line 5

def initialize(site)
  @site = site
end

Instance Method Details

#get_ipObject



14
15
16
17
18
19
20
21
22
# File 'lib/snackhack2/iplookup.rb', line 14

def get_ip
  ips = []
  ip = `ping -c 2 #{@site.gsub('https://', '')}`.lines
  ip.each do |l|
    new_ip = l.match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)
    ips << new_ip.to_s unless ips.include?(new_ip)
  end
  puts "IP via ping: #{ips.shift}\n\n\n\n"
end

#nslookupObject



24
25
26
27
28
29
# File 'lib/snackhack2/iplookup.rb', line 24

def nslookup
  ns = `nslookup #{@site.gsub('https://', '')}`.lines
  ns.each do |ip|
    puts ip if ip.include?('Address')
  end
end

#runObject



9
10
11
12
# File 'lib/snackhack2/iplookup.rb', line 9

def run
  get_ip
  nslookup
end