Skip to content

Instantly share code, notes, and snippets.

@burlesona
Created April 2, 2017 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burlesona/106167bf0b4521052d2e46bc39ecdb1b to your computer and use it in GitHub Desktop.
Save burlesona/106167bf0b4521052d2e46bc39ecdb1b to your computer and use it in GitHub Desktop.
For GT NS6262 class, a script to get IP addresses from hostnames
require 'resolv'
filename = ARGV[0]
batch_size = ARGV[1].to_i
outfile = File.open('ip-addresses.txt','w+')
domains = File.readlines(filename)
groups = domains.each_slice(batch_size)
threads = []
results = []
groups.each_with_index do |group,index|
threads << Thread.new do
result = group.map do |domain|
begin
ip = Resolv.getaddress(domain.chomp)
ip.include?(":") ? nil : ip
rescue
nil
end
end
results[index] = result
end
end
threads.each(&:join)
results.each do |batch|
batch.each do |ip|
outfile.puts ip
end
end
outfile.close
# To call from the command line on the class provided VM, with timing:
# time ruby lookup.rb <input file> <batch size>
# The first argument is the filename you want to scan
# The second argument is how many hosts each thread should scan
# Example:
# time ruby lookup.rb joe1-top-1ht.txt 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment