Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从 xinetd 通过流套接字启动的 Ruby 脚本中获取客户端 IP 地址?在 PHP 中,我只会使用stream_socket_get_name(STDIN, true);
stream_socket_get_name(STDIN, true);
提前致谢!
在搜索了很多解决方案之后,甚至试图在 Freenode 上的#ruby 频道上询问并被完全忽略,我终于找到了解决方案:
def to_ip(addr) (4...8).map{|x|addr[x]}.join('.') end socket = Socket.for_fd(STDIN.fileno) ip = to_ip(socket.getpeername)
希望这对某人有帮助!