#!/usr/bin/ruby
require 'rubygems'
require 'socket'
require 'net/ssh'
$file = ARGV[0]
$port = ARGV[1]
$address = ""
$result = ""
if ARGV.length != 2
puts "Usage: #{$0} <ip address list file> <port>"
exit 0
end
if !($file && FileTest.exists?("#{$file}"))
puts "Invalid input filename detected."
puts "Please ensure the filename is correct, the file exists, and is not just a single IP address."
exit 1
end
File.open("#{$file}", "r") do |infile|
while (line = infile.gets)
if line =~ /(\b(?:\d{1,3}\.){3}\d{1,3}\b)/
$address = line.chomp!
end
begin
t = TCPSocket.open("#{$address}", "#{$port}")
rescue
puts "#{$address}:#{$port} -- closed"
next
else
puts "#{$address}:#{$port} -- open"
t.close
end
cmd = "./findrpc #{$address} | grep #{$port}"
$result = `"#{cmd}"`
puts "#{$result}"
end
infile.close
end
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.