Last active
July 9, 2017 20:03
-
-
Save picatz/b3f025906ce7e3e8fdf19e33b0f9ca48 to your computer and use it in GitHub Desktop.
Crystal Port Scanner
This file contains hidden or 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
require "socket" | |
host = "target_ip" | |
ports = (1..1024).to_a | |
channel = Channel(Nil).new | |
semaphore = Mutex.new | |
spawn do | |
60.times do | |
spawn do | |
begin | |
while port = ports.pop | |
begin | |
s = TCPSocket.new(host, port, connect_timeout: 1) | |
semaphore.synchronize { puts port.to_s + " Open" } | |
rescue | |
semaphore.synchronize { puts port.to_s + " Closed" } | |
ensure | |
s.close if s | |
spawn do | |
channel.send(nil) # end of operation | |
end | |
end | |
end | |
rescue | |
# when ya' just can't pop no mo' | |
end | |
end | |
end | |
end | |
ports.size.times do | |
channel.receive | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment