Last active
January 31, 2017 12:09
-
-
Save snipsnipsnip/14ca07086dd2027ecc8f45cd218970e3 to your computer and use it in GitHub Desktop.
pingport.rb
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'socket' | |
ARGV.size == 2 or abort "usage: #$0 hostname port" | |
host, port = ARGV | |
sec = 1 | |
addr = Addrinfo.tcp(host, port) | |
puts "trying #{addr.inspect_sockaddr}" | |
s = Socket.new(addr.afamily, addr.socktype) | |
begin | |
s.connect_nonblock addr | |
rescue IO::WaitWritable | |
IO.select(nil, [s], nil, sec) or abort "TIMEOUT" | |
end | |
puts "OPEN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment