summaryrefslogtreecommitdiff
path: root/macto
blob: f43a7cc4fa68950c13aa0f6170d3647816e09ad8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env ruby

TO = ARGV.shift.chomp.downcase
MAC = ARGV.shift.chomp.gsub(/[.:]/, '')
UPPER = ARGV.shift ? true : false

if MAC.match(/[0-9a-fA-F]{12}/).nil? then
  puts "Not a valid MAC"
  exit 1
end

case TO
  when 'cisco'
    puts (UPPER ? MAC.upcase : MAC).scan(/[A-Fa-f0-9]{4}/).join('.')
  when 'canonical'
    puts (UPPER ? MAC.upcase : MAC).scan(/[A-Fa-f0-9]{2}/).join(':')
end