Edit: Complete rewrite of post.
I still want to say thanks to GoLangBridge for creating and cultivating this community.
I’ve simplified my code (technically mostly stolen the code from John Leon’s talk at GopherCon 2016 with a small change to use net package to retrieve the interface).
Now it is only attempting to open the interface and capture a single packet.
package main
import (
"fmt"
"log"
"net"
"time"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
)
var (
snapshotLength int32 = 65535
promiscuous bool = false
timeout time.Duration = -1 * time.Second
err error
handle *pcap.Handle
)
func main() {
device, err := net.InterfaceByName("Ethernet")
fmt.Println(device)
// Open Device
handle, err = pcap.OpenLive(device.Name, snapshotLength, promiscuous, timeout)
if err != nil {
log.Fatal("OpenLive Call: ", err)
}
defer handle.Close()
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
// Get the next packet
packet, err := packetSource.NextPacket()
if err != nil {
log.Fatal(err)
}
fmt.Println(packet)
}
This is my output.
&{5 1500 Ethernet 00:d8:61:33:8e:84 up|broadcast|multicast}
2019/10/20 14:24:19 OpenLive Call: Ethernet: Error opening adapter: The system cannot find the device specified. (20)
exit status 1
Go Version: 1.13.3
npcap Version: 0.9983 (Wireshark currently works as expected with this install)
Windows 10
Running Powershell and cmd as Administrator.
It looks like my problem is with npcap or Windows, but I’m stuck. Any tips for troubleshooting this further?