Last active
December 12, 2015 02:09
-
-
Save YoshihitoAso/4696911 to your computer and use it in GitHub Desktop.
ポートスキャンするスクリプトをRubyで書くとこんな感じ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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