Skip to content

Instantly share code, notes, and snippets.

@YoshihitoAso
Last active December 12, 2015 02:09
Show Gist options
  • Save YoshihitoAso/4696911 to your computer and use it in GitHub Desktop.
Save YoshihitoAso/4696911 to your computer and use it in GitHub Desktop.
ポートスキャンするスクリプトをRubyで書くとこんな感じ
// install net-ping
gem install net-ping
// script
#!/usr/local/bin/ruby
require 'rubygems'
require 'net/ping'
def portscan(ip = IPAddr.new('127.0.0.1'), ports = 1..65536)
ports.each { |p|
ping_tcp = Net::Ping::TCP.new(ip, p)
puts "#{ip} \t[#{p}]" if ping_tcp.ping?
}
end
# -----------------------------------
# main
# -----------------------------------
@input_file = ARGV[0] || "./pinglist.txt"
@ports = [
'http',
'https',
'ssh',
'ftp',
'telnet',
3389 #RDP
]
File::open( @input_file ) { |f|
f.each { |line|
portscan(line.chomp, @ports)
puts "-------------------------------"
}
}
// etc
for i in 1..254
portscan("192.168.0.#{i}", 1..65536)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment