summaryrefslogtreecommitdiff
path: root/macto
diff options
context:
space:
mode:
authorNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-09-18 11:51:28 +0100
committerNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-09-18 11:51:28 +0100
commitb0a14e013b318fa87714414b8ece95780527bddf (patch)
treea9427383ab6e38a4421c9c4313043f6dfcb8e90e /macto
Initial commit
Diffstat (limited to 'macto')
-rwxr-xr-xmacto17
1 files changed, 17 insertions, 0 deletions
diff --git a/macto b/macto
new file mode 100755
index 0000000..f43a7cc
--- /dev/null
+++ b/macto
@@ -0,0 +1,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