Class: Snackhack2::IpLookup
- Inherits:
-
Object
- Object
- Snackhack2::IpLookup
- Defined in:
- lib/snackhack2/iplookup.rb
Instance Attribute Summary collapse
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #get_ip ⇒ Object
-
#initialize(file_save: false) ⇒ IpLookup
constructor
A new instance of IpLookup.
- #nslookup ⇒ Object
- #run ⇒ Object
- #socket ⇒ Object
Constructor Details
#initialize(file_save: false) ⇒ IpLookup
Returns a new instance of IpLookup.
9 10 11 12 |
# File 'lib/snackhack2/iplookup.rb', line 9 def initialize(file_save: false) @file_save = file_save @site = site end |
Instance Attribute Details
#site ⇒ Object
Returns the value of attribute site.
7 8 9 |
# File 'lib/snackhack2/iplookup.rb', line 7 def site @site end |
Instance Method Details
#get_ip ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/snackhack2/iplookup.rb', line 20 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 if !new_ip.to_s.empty? && !ips.include?(new_ip) end ips end |
#nslookup ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/snackhack2/iplookup.rb', line 30 def nslookup ips = [] ns = `nslookup #{@site.gsub('https://', '')}`.lines ns.each do |ip| new_ip = ip.gsub('Address: ', '').strip if ip.include?('Address') if !ips.include?(new_ip) && !new_ip.nil? ips << new_ip.split('Addresses: ')[1].to_s end end if @file_save Snackhack2.file_save(@site, 'ip_lookup', ips.to_a.drop(1).join("\n")) else ips end end |
#run ⇒ Object
14 15 16 17 18 |
# File 'lib/snackhack2/iplookup.rb', line 14 def run get_ip nslookup socket end |
#socket ⇒ Object
48 49 50 |
# File 'lib/snackhack2/iplookup.rb', line 48 def socket puts IPSocket.getaddress(@site.gsub('https://', '')) end |