resolve.rb
#!/usr/bin/ruby -w
# This script takes a list of hostnames (one per line), resolves their address,
# then creates a new comma-seperated value file with each hostname followed by
# its IP address.
require 'resolv'
input = File.open("hosts.csv", "r")
output = File.open("hosts2.csv", "w")
input.each_line {|line|
line = line.chop
Resolv::DNS.new.each_address("#{line}") {|addr|
output.puts "#{line},#{addr}"
}
}
The above script can be extended using pipes to combine multiple commands such as Sed, Awk, Nmap, etc. The example below shows how you can take a given list of hostnames, resolve their IP addresses, remove duplicate IP’s, perform an Nmap scan and then output the results to an XML file.
$ ruby resolve.rb
$ sed 's/,/\ /' hosts2.csv | awk '{print $2}' | uniq | nmap -sS -A -T4 -iL - -oX scan_results.xml

#!/usr/bin/rubyrequire 'net/http'
$host = "uatree.0x58.com"
$path = "/submitted.html"
proxy_addr = "127.0.0.1"
proxy_port = 9050
$proxy_class = Net::HTTP::Proxy(proxy_addr, proxy_port)
$http = $proxy_class.new( $host, 80)
while true
post = $http.post( $path, "Nb_var00=0", nil )
end