Ruby:如何将IP范围转换为IP数组
发布时间:2020-12-17 04:01:30  所属栏目:百科  来源:网络整理 
            导读:有没有简单的方法将IP范围转换为IP数组? def convertIPrange (start_ip,end_ip) #output: array of ips endend 例如输入 ('192.168.1.105','192.168.1.108') 产量 ['192.168.1.105','192.158.1.106','192.158.1.107','192.158.1.108'] 解决方法 使用Ruby标
                
                
                
            | 
                         
 有没有简单的方法将IP范围转换为IP数组? 
  
  
  
def convertIPrange (start_ip,end_ip) #output: array of ips end end 例如输入 ('192.168.1.105','192.168.1.108') 
 产量 ['192.168.1.105','192.158.1.106','192.158.1.107','192.158.1.108'] 解决方法
 使用Ruby标准库 
  
        IPAddr 
  
  
 # I would suggest naming your function using underscore rather than camelcase # because of Ruby naming conventions # require 'ipaddr' def convert_ip_range(start_ip,end_ip) start_ip = IPAddr.new(start_ip) end_ip = IPAddr.new(end_ip) # map to_s if you like,you can also call to_a,# IPAddrs have some neat functions regarding IPs,# be sure to check them out # (start_ip..end_ip).map(&:to_s) end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
相关内容
- ruby-on-rails – 在Rails 4.0上安装Ruby时出错 – atomic_
 - oracle修改字段类型时报"要更改的列必须为空"处理方
 - ruby-on-rails – Rails:在开发环境中测试Cron Jobs
 - Ehcache(02)——ehcache.xml简介
 - Swift布尔文字(Obj-C @YES @NO等价物)
 - 日志记录 – 从多个服务器聚合多个日志文件的最佳方式
 - ruby-on-rails – 即使没有更改,也停止ActiveRecord保存序列
 - Cocos2d-x:截图背景空白
 - OpenFlashChart2的使用
 - ruby-on-rails – Rspec:检查数组是否包含包含属性的对象
 
