Class: Snackhack2::IpLookup
- Inherits:
-
Object
- Object
- Snackhack2::IpLookup
- Defined in:
- lib/snackhack2/iplookup.rb
Instance Method Summary collapse
- #get_ip ⇒ Object
-
#initialize(site) ⇒ IpLookup
constructor
A new instance of IpLookup.
- #nslookup ⇒ Object
- #run ⇒ Object
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_ip ⇒ Object
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 |
#nslookup ⇒ Object
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 |
#run ⇒ Object
9 10 11 12 |
# File 'lib/snackhack2/iplookup.rb', line 9 def run get_ip nslookup end |