Posted: April 20th, 2011 | Author: Dax | Filed under: Ruby | No Comments »
Here’s a short snippet of how to grab a domain’s nameserver info using Ruby.
require 'resolv'
a = []
dns = Resolv::DNS.new
dns.getresources("google.com", Resolv::DNS::Resource::IN::NS).collect {|n| a << n.name.to_s }
puts a
Posted: April 20th, 2011 | Author: Dax | Filed under: Ruby | No Comments »
This tutorial shows how you can read and write csv files in Ruby. I’m going to use a plugin called FasterCSV.
To install FasterCSV, type in your terminal:
sudo apt-get install fastercsv
In your ruby code:
require 'rubygems'
require 'faster_csv'
# Reading csv file
FasterCSV.foreach(csv_file, :quote_char => '"', :col_sep => ',', :row_sep => :auto) do |row|
puts row[0] # Output first cell
end
# Writing data into a csv file
FasterCSV.open("report.csv", "w") do |csv|
csv << ['Bulls','62','20']
csv << ['Spurs','61','21']
end
There are also other alternatives for parsing and writing csv files in Ruby. You can use CSV, CSVScan and CCSV