Página 1 de 1

[Ruby] LocateIP 0.3

Publicado: 27 Jun 2015, 01:17
por Doddy
Un simple script en Ruby para localizar una IP y sus DNS.

Version consola :
#!usr/bin/ruby
#LocateIP 0.3
#(C) Doddy Hackman 2015

require "open-uri"
require "net/http"  
require "resolv"

# Functions 

def get_ip(hostname)
	begin
		return Resolv.getaddress(hostname) 
	rescue
		return "Error"
	end
end

def toma(web)
	begin
		return open(web, "User-Agent" => "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0").read
	rescue
		return "Error"
	end
end

def response_code(web)
	begin
		return Net::HTTP.get_response(URI(web)) .code 
	rescue
		return "404"
	end
end

def tomar(web,arg)
	begin
		headers = {"User-Agent" => "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"}
		uri = URI(web)
		http = Net::HTTP.new(uri.host, uri.port)
		return http.post(uri.path,arg, headers).body
	rescue
		return "Error"
	end
end

def uso 
	print "\n[+] Sintax : ruby locateip.rb <target>\n"
end

def  head
	print "\n\n-- == LocateIP 0.3 == --\n\n"
end

def copyright
	print "\n\n-- == (C) Doddy Hackman 2015 == --\n\n"
end

def locateip(target)

	print "\n[+] Getting IP ...\n"

	ip = get_ip(target)

	print "\n[+] IP : "+ip+"\n"

	web = "http://www.melissadata.com/lookups/iplocation.asp"
	print "\n[+] Locating ...\n\n"

	code = tomar(web,"ipaddress="+ip+"&btn=Submit")

	if code=~/City<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
		print "[+] City : "+$2+"\n"
	else
		print "[+] City : Not Found\n"
	end

	if code=~/Country<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
		print "[+] Country : "+$2+"\n"
	else
		print "[+] Country : Not Found\n"
	end

	if code=~/State or Region<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
		print "[+] State or Region : "+$2+"\n";
	else
		print "[+] State of Region : Not Found\n"
	end

	print "\n[+] Getting DNS ...\n\n"

	control = "0"

	code = toma("http://www.ip-adress.com/reverse_ip/"+ip)

	dnss = code.scan(/whois\/(.*?)\">Whois/)

	dnss.flatten.each do |dns|
		begin
			if dns != ""
				control = "1"
				print "[+] DNS Found : "+dns
			end
		end
	end

	if control=="0"
		print "\n[-] DNS Not Found\n"
	end
end

target = ARGV[0]

head()

if !target
	uso()
else
	locateip(target)
end

copyright()

#The End ?
Version Tk :
#!usr/bin/ruby
#LocateIP 0.3
#(C) Doddy Hackman 2015

require "tk"
require "open-uri"
require "net/http" 
require "resolv"

# Functions 

def get_ip(hostname)
	begin
		return Resolv.getaddress(hostname) 
	rescue
		return "Error"
	end
end

def toma(web)
	begin
		return open(web, "User-Agent" => "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0").read
	rescue
		return "Error"
	end
end

def response_code(web)
	begin
		return Net::HTTP.get_response(URI(web)) .code 
	rescue
		return "404"
	end
end

def tomar(web,arg)
	begin
		headers = {"User-Agent" => "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"}
		uri = URI(web)
		http = Net::HTTP.new(uri.host, uri.port)
		return http.post(uri.path,arg, headers).body
	rescue
		return "Error"
	end
end

#

window = TkRoot.new { title "LocateIP 0.3 (C) Doddy Hackman 2015" ; background "black" }
window['geometry'] = '300x300-20+10'

TkLabel.new(window) do
	background "black"
	foreground "yellow"
	text "    Target : "
	place('relx'=>"0.1",'rely'=>"0.1")
end

target = TkEntry.new(window){
	background "black"
	foreground "yellow"
	width 25
	place('relx'=>0.3,'rely'=>0.1)
}

TkLabel.new(window) do
	background "black"
	foreground "yellow"
	text "Console"
	place('relx'=>0.4,'rely'=>0.2)
end

console =TkText.new(window) do
	background "black"
	foreground "yellow"
	width 30
	height 10
	place('relx'=>0.1,'rely'=>0.3)
end

TkButton.new(window) do
	text "Search"
        background "black"
	foreground "yellow"
	width 17
	activebackground "yellow"
	highlightbackground  "yellow"
	command proc{
	
		target = target.value.to_s
	
		console.insert("end",  "[+] Getting IP ...\n")

		ip = get_ip(target)

		web = "http://www.melissadata.com/lookups/iplocation.asp"

		console.insert("end", "\n[+] Locating ...\n\n")

		code = tomar(web,"ipaddress="+ip+"&btn=Submit")

		if code=~/City<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
			console.insert("end", "[+] City : "+$2+"\n")
		else
			console.insert("end", "[+] City : Not Found\n")
		end

		if code=~/Country<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
			console.insert("end","[+] Country : "+$2+"\n")
		else
			console.insert("end", "[+] Country : Not Found\n")
		end

		if code=~/State or Region<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
			console.insert("end", "[+] State or Region : "+$2+"\n")
		else
			console.insert("end","[+] State of Region : Not Found\n")
		end

		console.insert("end","\n[+] Getting DNS ...\n\n")

		control = "0"

		code = toma("http://www.ip-adress.com/reverse_ip/"+ip)

		dnss = code.scan(/whois\/(.*?)\">Whois/)

		dnss.flatten.each do |dns|
			begin
				if dns != ""
					control = "1"
					console.insert("end", "[+] DNS Found : "+dns)
				end
			end
		end

		if control=="0"
			console.insert("end","\n[-] DNS Not Found\n")
		end

		console.insert("end","\n\n[+] Finished")
		
	}
	place('relx'=>0.3,'rely'=>0.9)
end

Tk.mainloop

#The End ?
Una imagen :

Imagen


Eso es todo.