Posted by admin on August 6, 2009 – 10:13 am
Filed under ruby
Tagged as argument, ARGV, cli, close, close file, command line argument, convert, converter, domain, domain name, exception, file, http, ip, ip address, open, open file, open-uri, open-uri exception, OpenURI::HTTPError, ruby, snippet, Timeout::Error, uri, url
Author: slac3dork
Site: http://snippet.c0de.me
Summary: Reverse IP tool. Ruby code to get domain name from ip address and save all results to ip2domain_result.txt. This script need internet connection and create connection to http://www.ip-adress.com/reverse_ip/. Tested on Linux.
Usage: ruby ip2domain.rb <domain_name> or ./ip2domain.rb <domain_name>
#!/usb/bin/ruby
# _________ .__ .____ _______
# / _____/ ____ |__|_____ | | \ _ \ ____
# \_____ \ / \| \____ \| | / /_\ \ / ___\
# / \ | \ | |_> > |__\ \_/ \/ /_/ >
#/_______ /___| /__| __/|_______ \_____ /\___ /
# \/ \/ |__| \/ \//_____/
# http://snippet.c0de.me
# slac3dork[at]gmail[dot]com
require 'open-uri'
if ARGV.size < 1
puts '[-] Usage ./ip2domain.rb <ip_address>'
exit 1
end
puts '-----------------------------------------------'
puts '[+] Reverse IP tool'
puts '[+] ip2domain.rb'
puts '[+] Author: slac3dork'
puts "-----------------------------------------------\n\n"
begin
status = false
filename = 'ip2domain_result.txt'
ip_addr = ARGV[0]
domain_file = File.new("#{filename}", "w")
open("http://www.ip-adress.com/reverse_ip/#{ip_addr}") {|page|
page.each_line {|line|
if (line =~ /.*<\/td>/)
domain_name = "#{line.slice(/\S.*/).slice(/([a-z0-9_-]+[\.]{1})+[a-z]{2,}/)}"
if (domain_name != '')
if (domain_file)
puts "[+] #{domain_name}"
domain_file.puts("#{domain_name}")
else
puts 'Unable to open file'
exit(1)
end
if (!status)
status = true
end
end
end
}
}
domain_file.close
if (!status)
puts '[-] Not found. Check your IP address.'
else
puts '--> All domain name results has been saved to ip2domain_result.txt'
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
