Class: Jungler

Inherits:
Object
  • Object
show all
Defined in:
lib/jungler.rb,
lib/jungler/version.rb

Constant Summary collapse

IP_REGEX =
/IN\s+A\s+(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})/
NS_REGEX =
/IN\s+NS\s+([\w-]*\.+[\w-]+\.+[\w-]+\.+)/
VERSION =
"0.0.1".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ Jungler

Returns a new instance of Jungler.



6
7
8
# File 'lib/jungler.rb', line 6

def initialize(domain)
  @domain = domain
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



2
3
4
# File 'lib/jungler.rb', line 2

def domain
  @domain
end

Instance Method Details

#corresponding_ipObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/jungler.rb', line 16

def corresponding_ip
  packet = Net::DNS::Resolver.start(@domain)
  answer = packet.answer.join('')
  ips = answer.scan(IP_REGEX)
  ips.each do |ip|
    ip = ip.first
    puts "#{domain} is hosted on IP : #{ip}\n"
  end
  puts "-----------------------------------------"
end

#ns_recordsObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jungler.rb', line 27

def ns_records
  packet = Net::DNS::Resolver.start(domain, Net::DNS::NS)
  answer = packet.answer.join('')
  nss = answer.scan(NS_REGEX)
  i = 1
  nss.each do |ns|
    ns = ns.first
    puts "Name server #{i} for domain #{@domain} : #{ns}\n"
    i += 1
  end
  puts "-----------------------------------------"
end

#ping_statusObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/jungler.rb', line 40

def ping_status
  Net::Ping::TCP.service_check = true

  pt = Net::Ping::TCP.new(@domain)
  if pt.ping
    puts "#{@domain} is alive."
  else
    puts "#{@domain} seems to be dead or is not reachable."
  end
end

#stalkObject



10
11
12
13
14
# File 'lib/jungler.rb', line 10

def stalk
  corresponding_ip
  ns_records
  ping_status
end