D
Derek Smith
Hi All,
Is there a ruby substitute for lsof's functionality? Meaning I want to
listen on certain ports/sockets such as identd's port 113 to see if any
process is using this port. Is this possible in Ruby w/out using lsof?
Here is my test code, on my ubuntu personal laptop with a port from
netstat -a.
#!/usr/bin/ruby -w
require 'rubygems'
require 'socket'
#TCPSocket.open('localhost', '34814') do |socket|
# socket.puts "gibberish"
# socket.each_line do |line|
# p line
# end
#end
require 'socket'
host = 'localhost'
port = 47408
s = TCPSocket.open(host, port)
while line = s.gets
puts line.chop
end
s.close
In both cases, I get the error:
derek@vaio-ubuntu:~$ sudo ruby port_tst.rb
port_tst.rb:18:in `initialize': Connection refused - connect(2)
(Errno::ECONNREFUSED)
from port_tst.rb:18:in `open'
from port_tst.rb:18
thank you!
Is there a ruby substitute for lsof's functionality? Meaning I want to
listen on certain ports/sockets such as identd's port 113 to see if any
process is using this port. Is this possible in Ruby w/out using lsof?
Here is my test code, on my ubuntu personal laptop with a port from
netstat -a.
#!/usr/bin/ruby -w
require 'rubygems'
require 'socket'
#TCPSocket.open('localhost', '34814') do |socket|
# socket.puts "gibberish"
# socket.each_line do |line|
# p line
# end
#end
require 'socket'
host = 'localhost'
port = 47408
s = TCPSocket.open(host, port)
while line = s.gets
puts line.chop
end
s.close
In both cases, I get the error:
derek@vaio-ubuntu:~$ sudo ruby port_tst.rb
port_tst.rb:18:in `initialize': Connection refused - connect(2)
(Errno::ECONNREFUSED)
from port_tst.rb:18:in `open'
from port_tst.rb:18
thank you!