Skip to content

Instantly share code, notes, and snippets.

@kevinzhow
Created March 20, 2014 11:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinzhow/9661753 to your computer and use it in GitHub Desktop.
Save kevinzhow/9661753 to your computer and use it in GitHub Desktop.
路由转换
#utf-8
require 'netaddr'
newfile = File.open("some_file", "w")
File.foreach('out_ip').with_index { |line, line_num|
line = line.split(',')[0].to_s
a = NetAddr::CIDR.create(line)
puts "#{a.ip}/#{a.wildcard_mask}"
newfile.write("route = #{a.ip}/#{a.wildcard_mask}\n")
}
newfile.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment