Tag Archives: domain to ip

Ruby – Domain Name to IP address

0
Filed under ruby
Tagged as , , , , , , , , , , , , , ,

Author: slac3dork
Site: http://snippet.c0de.me
Summary: Reverse DNS lookup tool. Ruby code to get IP address from domain name. This script need internet connection and create connection to http://www.ip-adress.com/whois/. Tested on Linux.
Usage: ruby domain2ip.rb <domain_name> or ./domain2ip.rb <domain_name>

#!/usb/bin/ruby

#  _________      .__       .____   _______
# /   _____/ ____ |__|_____ |    |  \   _  \    ____
# \_____  \ /    \|  \____ \|    |  /  /_\  \  / ___\
# /        \   |  \  |  |_> >    |__\  \_/   \/ /_/  >
#/_______  /___|  /__|   __/|_______ \_____  /\___  /
#        \/     \/   |__|           \/     \//_____/
# http://snippet.c0de.me
# slac3dork[at]gmail[dot]com

require 'open-uri'

if ARGV.size < 1
puts '[-] Usage ./domain2ip.rb <domain_name>'
exit 1
end

puts '-----------------------------------------------'
puts '[+] Reverse DNS Lookup tool'
puts '[+] domain2ip.rb'
puts '[+] Author: slac3dork'
puts "-----------------------------------------------\n\n"

begin
        status = false
        domain_name = ARGV[0]
        open("http://www.ip-adress.com/whois/#{domain_name}") {|page|
            page.each_line {|line|
                    if (line =~ /#{domain_name} IP address: /)
                            puts "[+] #{line.slice(/#{domain_name} IP address: ([0-9]{1,3}[\.]{1}){3}[0-9]{1,3}/)}"
                        status = true
                    end

                }
           }
        if (!status)
                puts '[-] Not found. Check your domain name.'
        end
rescue OpenURI::HTTPError => error_msg
        puts "[-] Ups! Got bad status code: #{error_msg}. Try again"
rescue Timeout::Error
        puts '[-] oops! Timeout bro, check your internet connection'
rescue Exception => e
        puts "#{e.message}"
end

ruby,code,code,snippet