mirror of
https://github.com/maride/pancap.git
synced 2024-11-25 01:54:24 +00:00
Init commit: open file and print link type
This commit is contained in:
commit
daa3cfd812
20
src/analyzer.go
Normal file
20
src/analyzer.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
"log"
|
||||
)
|
||||
|
||||
// Analyzes the given packet source
|
||||
func analyzePCAP(source *gopacket.PacketSource, linkType layers.LinkType) error {
|
||||
log.Printf("PCAP capture link type is %s (ID %d)", getNameOfLinkType(linkType), linkType)
|
||||
// TODO: maybe, just maybe, we wanna print more here than just the link type :)
|
||||
_, _ = source, linkType
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns the name of the LinkType constant handed over
|
||||
func getNameOfLinkType(lt layers.LinkType) string {
|
||||
return lt.String()
|
||||
}
|
31
src/file.go
Normal file
31
src/file.go
Normal file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
"github.com/google/gopacket/pcap"
|
||||
)
|
||||
|
||||
var (
|
||||
filenameFlag *string
|
||||
)
|
||||
|
||||
// Registers the flag --file
|
||||
func registerFileFlags() {
|
||||
filenameFlag = flag.String("file", "", "PCAP file to base analysis on")
|
||||
}
|
||||
|
||||
// Opens the PCAP, returns its packets and the link type or an error
|
||||
func openPCAP() (*gopacket.PacketSource, layers.LinkType, error) {
|
||||
// Open specified file
|
||||
handle, openErr := pcap.OpenOffline(*filenameFlag)
|
||||
if openErr != nil {
|
||||
// There were some problems opening the file
|
||||
return nil, 0, openErr
|
||||
}
|
||||
|
||||
// Open given handle as packet source and return it
|
||||
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
|
||||
return packetSource, handle.LinkType(), nil
|
||||
}
|
40
src/main.go
Normal file
40
src/main.go
Normal file
@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// important things first
|
||||
printMOTD()
|
||||
|
||||
// register flags
|
||||
registerFileFlags()
|
||||
flag.Parse()
|
||||
|
||||
// Open the given PCAP
|
||||
packetSource, linkType, fileErr := openPCAP()
|
||||
if fileErr != nil {
|
||||
// Encountered problems with the PCAP - permission and/or existance error
|
||||
log.Fatalf("Error occured while opeining specified file: %s", fileErr.Error())
|
||||
}
|
||||
|
||||
// Start analyzing
|
||||
analyzeErr := analyzePCAP(packetSource, linkType)
|
||||
if analyzeErr != nil {
|
||||
// Mh, encountered some problems while analyzingfil
|
||||
log.Fatalf("Error occurred while analyzing: %s", analyzeErr.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Prints a simple figlet-style ASCII art
|
||||
func printMOTD() {
|
||||
fmt.Println(" _ __ __ _ _ __ ___ __ _ _ __")
|
||||
fmt.Println("| '_ \\ / _` | '_ \\ / __/ _` | '_ \\")
|
||||
fmt.Println("| |_) | (_| | | | | (_| (_| | |_) |")
|
||||
fmt.Println("| .__/ \\__,_|_| |_|\\___\\__,_| .__/")
|
||||
fmt.Println("|_| |_|")
|
||||
fmt.Println("PanCAP: Analyzer for capture files\n")
|
||||
}
|
Loading…
Reference in New Issue
Block a user