Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/tools/recon/makeiplist.rb
Views: 11767
#!/usr/bin/env ruby12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67#8# This script takes a list of ranges and converts it to a per line IP list.9# Demonstration:10# echo 192.168.100.0-50 >> rangelist.txt11# echo 192.155-156.0.1 >> rangelist.txt12# echo 192.168.200.0/25 >> rangelist.txt13# ruby tools/recon/makeiplist.rb14#15# Author:16# mubix17#1819msfbase = __FILE__20while File.symlink?(msfbase)21msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))22end2324$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))2526require 'rex'27require 'optparse'2829class OptsConsole30def self.parse(args)31options = {}3233opts = OptionParser.new do |opts|34opts.banner = %Q|This script takes a list of ranges and converts it to a per line IP list.35Usage: #{__FILE__} [options]|3637opts.separator ""38opts.separator "Specific options:"3940opts.on("-i", '-i <filename>', "Input file") do |v|41options['input'] = v.to_s42end4344opts.on("-o", '-o <filename>', "(Optional) Output file. Default: iplist.txt") do |v|45options['output'] = v.to_s46end4748opts.separator ""49opts.separator "Common options:"5051opts.on_tail("-h", "--help", "Show this message") do52puts opts53exit54end55end5657opts.parse!(args)58if options.empty?59puts "[*] No options specified, try -h for usage"60exit61end6263begin64if options['input'] == nil65puts opts66raise OptionParser::MissingArgument, '-i is a required argument'67end68unless ::File.exist?(options['input'])69raise OptionParser::InvalidArgument, "Not found: #{options['input']}"70end71if options['output'] == nil72options['output'] = 'iplist.txt'73end74rescue OptionParser::InvalidOption75puts "[*] Invalid option, try -h for usage"76exit77rescue OptionParser::InvalidArgument => e78puts "[*] #{e.message}"79exit80end8182options83end84end8586#87# Prints IPs88#89def make_list(in_f, out_f)90in_f.each_line do |range|91ips = Rex::Socket::RangeWalker.new(range)92ips.each do |ip|93out_f.puts ip94end95end96end9798#99# Returns file handles100#101def load_files(in_f, out_f)102handle_in = ::File.open(in_f, 'r')103104# Output file not found, assuming we should create one automatically105::File.open(out_f, 'w') {} unless ::File.exist?(out_f)106107handle_out = ::File.open(out_f, 'a')108109return handle_in, handle_out110end111112options = OptsConsole.parse(ARGV)113in_f, out_f = load_files(options['input'], options['output'])114115begin116puts "[*] Generating list at #{options['output']}"117make_list(in_f, out_f)118ensure119# Always makes sure the file descriptors are closed120in_f.close121out_f.close122end123124puts "[*] Done."125126127