如何用ruby获取本机IP

来源:互联网 发布:网络销售公司有些什么 编辑:程序博客网 时间:2024/06/06 02:43
require 'socket' def local_ip  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true  # turn off reverse DNS resolution temporarily   UDPSocket.open do |s|    s.connect '64.233.187.99', 1    s.addr.last  endensure  Socket.do_not_reverse_lookup = origend p local_ip()


原创粉丝点击