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 ⇒ IpLookup
constructor
A new instance of IpLookup.
- #nslookup ⇒ Object
- #run ⇒ Object
- #socket ⇒ Object
Constructor Details
#initialize ⇒ IpLookup
Returns a new instance of IpLookup.
6 7 8 |
# File 'lib/snackhack2/iplookup.rb', line 6 def initialize @site = site end |
Instance Attribute Details
#site ⇒ Object
Returns the value of attribute site.
5 6 7 |
# File 'lib/snackhack2/iplookup.rb', line 5 def site @site end |
Instance Method Details
#get_ip ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/snackhack2/iplookup.rb', line 16 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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/snackhack2/iplookup.rb', line 26 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) if !new_ip.nil? ips << new_ip end end end Snackhack2::file_save(@site, "ip_lookup", ips.to_a.drop(1).join("\n")) end |
#run ⇒ Object
10 11 12 13 14 |
# File 'lib/snackhack2/iplookup.rb', line 10 def run get_ip nslookup socket end |
#socket ⇒ Object
41 42 43 |
# File 'lib/snackhack2/iplookup.rb', line 41 def socket puts IPSocket::getaddress(@site.gsub("https://", "")) end |