MACGo: A Go Package for Handling MAC Addresses
MACGo is a Go package that provides tools for working with MAC addresses. It simplifies common tasks such as generating random MAC addresses, validating MAC addresses, and retrieving the vendor information associated with a MAC address.
Features
- Generate random MAC addresses.
- Check the validity of a MAC address.
- Retrieve the vendor information for a MAC address.
Installation
To install the MACGo package, use the go get
command:
go get github.com/rprata/macgo
Usage
Generate a Random MAC Address
package main
import (
"fmt"
"github.com/rprata/macgo/generator"
)
func main() {
randomMAC := macgo.GenerateRandomMAC(48)
fmt.Println("Random MAC Address:", randomMAC)
randomRaspberryPiMAC := generator.GenerateRandomMACAddressByVendor("raspberry")
fmt.Println("Random MAC Address (Raspberry PI): ", randomRaspberryPiMAC)
}
Check if a MAC Address is Valid
package main
import (
"fmt"
"github.com/rprata/macgo/checker"
)
func main() {
macAddress := "00:1A:2B:3C:4D:5E"
if checker.IsValidMACAddress(macAddress) {
fmt.Printf("%s is a valid MAC address\n", macAddress)
} else {
fmt.Printf("%s is not a valid MAC address\n", macAddress)
}
}
package main
import (
"fmt"
"github.com/rprata/macgo/lookup"
)
func main() {
macAddress := "00:1A:2B:3C:4D:5E"
vendorInfo, err := macgo.GetVendorInfo(macAddress)
if err != nil {
fmt.Printf("Error getting vendor info: %s\n", err)
} else {
fmt.Printf("Vendor: %s\n", vendorInfo)
}
}
MACGo CLI
The MACGo CLI is a command-line tool designed to provide functionalities related to MAC addresses, such as generation and vendor information lookup. It leverages the following Go packages for its operations:
- macgo/checker: A package for validating MAC addresses.
- macgo/generator: A package for generating random MAC addresses.
- macgo/lookup: A package for retrieving vendor information by MAC address.
Usage
The MACGo CLI offers the following commands:
1. Generate a Random MAC Address
Use the generate
command to generate a random MAC address. You can also specify a vendor name to generate a MAC address associated with that vendor.
macgo generate [-v, --vendor <vendor-name>]
-v, --vendor <vendor-name>
: Optional flag to specify a vendor name for generating a MAC address.
Example:
macgo generate
macgo generate -v "Cisco"
Use the lookup
command to retrieve vendor information for a given MAC address.
macgo lookup <mac-address>
<mac-address>
: The MAC address for which you want to retrieve vendor information.
Example:
macgo lookup 00:1A:2B:3C:4D:5E
3. Verify if MAC address is valid
Use the check
command to check if MAC address is valid.
macgo check <mac-address>
<mac-address>
: The MAC address for which you want to check.
Example:
macgo check 00:1A:2B:3C:4D:5E
How to Run
To run the MACGo CLI, build and execute the binary. Here are the general steps:
-
Install the CLI:
go install yourproject/app
-
Run the CLI:
macgo <command>
Replace <command>
with one of the available commands, such as generate
or lookup
.
Examples
Here are some examples of how to use the MACGo CLI:
-
Generate a random MAC address:
macgo generate
-
Generate a random MAC address for a specific vendor (e.g., Cisco):
macgo generate -v "Cisco"
-
Lookup vendor information for a MAC address (e.g., 00:1A:2B:3C:4D:5E):
macgo lookup 00:1A:2B:3C:4D:5E
-
Verify MAC address (e.g., 00:1A:2B:3C:4D:5E):
macgo check 00:1A:2B:3C:4D:5E
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions to macgo are welcome! Please read our Contribution Guidelines for more information on how to get involved.