Skip to content

Instantly share code, notes, and snippets.

@pramos
Last active July 17, 2022 20:38
Show Gist options
  • Save pramos/06bb938e66e4e298f8d4ec56060a39a0 to your computer and use it in GitHub Desktop.
Save pramos/06bb938e66e4e298f8d4ec56060a39a0 to your computer and use it in GitHub Desktop.
Go Script to enumerate all available network interfaces on a machine. Relies on gopacket.
package main
import (
"fmt"
"log"
"github.com/google/gopacket/pcap"
)
func main() {
devices, err := pcap.FindAllDevs()
if err != nil {
log.Fatalf("error retrieving devices - %v", err)
}
for _, device := range devices {
fmt.Printf("Device Name: %s\n", device.Name)
fmt.Printf("Device Description: %s\n", device.Description)
fmt.Printf("Device Flags: %d\n", device.Flags)
for _, iaddress := range device.Addresses {
fmt.Printf("\tInterface IP: %s\n", iaddress.IP)
fmt.Printf("\tInterface NetMask: %s\n", iaddress.Netmask)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment