Guest User

Untitled

a guest
Jan 25th, 2016
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'ipaddress'
  2.  
  3. ips = [
  4. '192.168.1.2/32',
  5. '10.0.3.5/32',
  6. '10.0.3.5/29',
  7. '10.0.0.0/24',
  8. '10.10.0.0/23',
  9. '192.168.1.0/29',
  10. '192.168.1.3/32',
  11. '192.168.1.4/31',
  12. '192.168.1.5/24',
  13. '172.16.0.0/16',
  14. '172.16.0.1/32'
  15. ]
  16.  
  17. puts "Before sorting"
  18. puts ips.inspect
  19. puts
  20.  
  21. ips.sort! do |x,y|
  22. x = IPAddress::IPv4.new(x)
  23. y = IPAddress::IPv4.new(y)
  24.  
  25. (y.prefix <=> x.prefix) || (x.address <=> y.address)
  26. end
RAW Paste Data