Skip to content

Instantly share code, notes, and snippets.

@hirose31
Created July 9, 2015 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirose31/47496cdd022c5e88632e to your computer and use it in GitHub Desktop.
Save hirose31/47496cdd022c5e88632e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'socket'
$stdout.sync = true
$stderr.sync = true
@lock = Mutex.new
def main
th = []
n = 300
err = 0
for i in 1..n
th << Thread.new(i) do |i|
begin
ip = Socket.getaddrinfo('www.irori.org', nil)
rescue SocketError => e
@lock.synchronize do
err += 1
end
puts format("[%6d] %s\n", i, e)
else
puts format("[%6d] %s\n", i, ip[0][3])
end
end
end
th.each {|t| t.join}
puts RUBY_VERSION
puts format("failed %d/%d %.2f%%", err, n, err.to_f/n.to_f*100)
exit 0
end
main if __FILE__ == $PROGRAM_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment