Skip to content

Commit 14e2aba

Browse files
committed
Initial commit
0 parents  commit 14e2aba

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Release/*

Build.cmd

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@echo off
2+
3+
if not exist "Release" md "Release"
4+
5+
set APP=oui_standardize
6+
7+
set GOARCH=amd64
8+
call :Build_OS
9+
10+
set GOARCH=386
11+
call :Build_OS
12+
13+
pause
14+
exit /b
15+
16+
:Build_OS
17+
18+
set GOOS=windows
19+
set EXT=.exe
20+
set INC=include_windows.go
21+
call :Build
22+
23+
set GOOS=linux
24+
set EXT=
25+
set INC=include_other.go
26+
call :Build
27+
28+
if %GOARCH% == 386 exit /b
29+
30+
set GOOS=darwin
31+
set EXT=.app
32+
set INC=include_other.go
33+
call :Build
34+
35+
exit /b
36+
37+
:Build
38+
39+
echo Building %APP%_%GOOS%_%GOARCH%%EXT%...
40+
go build -ldflags="-s -w" -o "Release/%APP%_%GOOS%_%GOARCH%%EXT%" %APP%.go %INC%
41+
42+
exit /b

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 ScriptTiger
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/thescripttiger%40gmail.com)
2+
3+
# oui_standardize
4+
oui_standardize standardizes IEEE MAC address block files (CSV files) containing OUI records by importing an arbitrary number of said files, sorting them by MAC address prefix, and then outputting the results to standard output (stdout). Curly brackets are used as delimiters and multi-line fields are reduced to single lines in order to allow scripts to more easily parse the records with as little overhead as possible.
5+
6+
Usage: `oui_standardize [<file>] [<file>] [<file>]...`
7+
8+
# More About ScriptTiger
9+
10+
For more ScriptTiger scripts and goodies, check out ScriptTiger's GitHub Pages website:
11+
https://scripttiger.github.io/
12+
13+
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MZ4FH4G5XHGZ4)
14+
15+
Donate Monero (XMR): 441LBeQpcSbC1kgangHYkW8Tzo8cunWvtVK4M6QYMcAjdkMmfwe8XzDJr1c4kbLLn3NuZKxzpLTVsgFd7Jh28qipR5rXAjx

include_other.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package main
2+
3+
//Set line endings to LF
4+
const eol = "\n"

include_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package main
2+
3+
//Set line endings to CRLF
4+
const eol = "\r\n"

oui_standardize.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"io"
6+
"encoding/csv"
7+
"strings"
8+
"sort"
9+
)
10+
11+
var data []string
12+
13+
func readCSV(file string) {
14+
15+
raw, err := os.Open(file)
16+
if err != nil {panic(err)}
17+
defer raw.Close()
18+
19+
reader := csv.NewReader(raw)
20+
21+
// Skip header line
22+
reader.Read()
23+
24+
for {
25+
// Read CSV line
26+
line, err := reader.Read()
27+
28+
// Validate line
29+
if err == io.EOF {break}
30+
if err != nil {panic(err)}
31+
32+
// Remove multi-line strings from addresses
33+
line[3] = strings.Replace(line[3], "\r", "", -1)
34+
line[3] = strings.Replace(line[3], "\n", " ", -1)
35+
36+
// Null-separated strings, starting with mac prefix
37+
data = append(data, strings.Join([]string{line[1], line[0], line[2], line[3]}, "\x00"))
38+
}
39+
40+
}
41+
42+
func help() {
43+
44+
os.Stdout.WriteString("Usage: oui_standardize [<file>] [<file>] [<file>]...\n")
45+
os.Exit(0)
46+
47+
}
48+
49+
func main() {
50+
51+
//Display help and exit if not enough arguments
52+
if len(os.Args) < 2 {help()}
53+
54+
// Treat arguments as file paths and read all files into data
55+
for i := 1; i < len(os.Args); i++ {readCSV(os.Args[i])}
56+
57+
// Sort data
58+
sort.Strings(data)
59+
60+
// Format and output
61+
for _, line := range data {
62+
fields := strings.Split(line, "\x00")
63+
os.Stdout.WriteString(
64+
"{"+fields[1]+"}{"+fields[0]+"}{"+fields[2]+"}{"+fields[3]+"}"+eol)
65+
}
66+
67+
}

0 commit comments

Comments
 (0)