ROR 获取ip

来源:互联网 发布:淘宝网知识产权 编辑:程序博客网 时间:2024/05/17 04:44

require 'socket'

 

 

local_ip=IPSocket.getaddress(Socket.gethostname) #本地机IP


server_ip=(require 'open-uri' ; open("http://myip.dk") { |f| /([0-9]{1,3}/.){3}[0-9]{1,3}/.match(f.read)[0].to_a[0] })  #服务端IP