문제

How can I get the client IP Address from inside a Ruby script that is launched by xinetd through a stream socket? In PHP I would just use stream_socket_get_name(STDIN, true);

Thanks in advance!

도움이 되었습니까?

해결책

After searching a lot for the solution, and even trying to ask on the #ruby channel on Freenode and being completely ignored, I've finally found the solution:

def to_ip(addr)
  (4...8).map{|x|addr[x]}.join('.')
end

socket = Socket.for_fd(STDIN.fileno)
ip = to_ip(socket.getpeername)

Hope this helps someone!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top