-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_maxtcp.rb
45 lines (34 loc) · 838 Bytes
/
check_maxtcp.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env ruby
=begin
You might want to raise ulimit : ulimit -n XXXXX
=end
require 'socket'
host = ARGV[0]
port = ARGV[1]
n = 65535
delay = 100 # max opened TCPSocket per sec
idle_time = 90
sockets = []
puts "Usage : check_maxtcp.rb <host> <port>"
n.times do |n|
begin
socket = TCPSocket.new(host,port)
sockets<<socket
if n%100 == 0
puts n.to_s + " sockets created."
end
sleep(1/delay)
rescue Exception => e
puts "Unable to connect. Stopped at attempt number " + n.to_s
puts e
break
end
end
puts sockets.size().to_s + " sockets created."
#uncomment to DOS for a period of time
#puts "Going to sleep for " + idle_time.to_s + " seconds."
#sleep(idle_time)
sockets.each do |socket|
socket.close
end
puts "Sockets are now closed