Skip to content

Instantly share code, notes, and snippets.

@pyther
Created May 2, 2020 05:11
Show Gist options
  • Save pyther/d8ad389358cffa3ef96b81105fdc6763 to your computer and use it in GitHub Desktop.
Save pyther/d8ad389358cffa3ef96b81105fdc6763 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
"github.com/google/gopacket/layers"
"log"
)
const etherTypeEap uint16 = 0x888E
var (
handle *pcap.Handle
err error
)
func main() {
handle, err = pcap.OpenOffline("eap.pcap")
if err != nil {
log.Fatal("unable to open pcap file")
}
defer handle.Close()
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
for packet := range packetSource.Packets() {
printPacketInfo(packet)
}
}
func printPacketInfo(packet gopacket.Packet) {
ethernetLayer := packet.Layer(layers.LayerTypeEthernet)
eapolLayer := packet.Layer(layers.LayerTypeEAPOL)
// Let's see if the packet is an ethernet packet
if ethernetLayer == nil {
fmt.Println("skipping packet")
return
}
ethernetPacket, _ := ethernetLayer.(*layers.Ethernet)
// Let's see if we have an EAPOL Packet
if eapolLayer == nil {
fmt.Println("Not an EAP packet, skipping...")
return
}
eapol, _ := eapolLayer.(*layers.EAPOL)
fmt.Printf("%s: %s v%d, len %d", ethernetPacket.SrcMAC, eapol.Type, eapol.Version, eapol.Length)
fmt.Println()
}
func EAPTypeString(code layers.EAPCode) string {
switch code {
case 1:
return "Request"
case 2:
return "Response"
case 3:
return "Success"
case 4:
return "Failure"
}
return "Unknown"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment