MCPcopy Create free account
hub / github.com/codeyourweb/irma / NetworkAnalysisRoutine

Function NetworkAnalysisRoutine

networkcapture.go:17–58  ·  view source on GitHub ↗

NetworkAnalysisRoutine dump network interfaces traffic

(bpffilter string, filename string, verbose bool)

Source from the content-addressed store, hash-verified

15
16// NetworkAnalysisRoutine dump network interfaces traffic
17func NetworkAnalysisRoutine(bpffilter string, filename string, verbose bool) {
18 // Check if WinPCAP installed
19 if _, err := os.Stat(os.Getenv("SystemRoot") + "\\System32\\wpcap.dll"); os.IsNotExist(err) {
20 logMessage(LOG_ERROR, "[ERROR] The network capture system requires the installation of WinPCAP on the workstation")
21 return
22 }
23
24 // Get a list of all interfaces.
25 ifaces, err := net.Interfaces()
26 if err != nil {
27 panic(err)
28 }
29
30 // Get a list of all devices
31 devices, err := pcap.FindAllDevs()
32 if err != nil {
33 panic(err)
34 }
35
36 // Creating pcap file
37 _, err = os.Stat(filepath.Dir(filename))
38 if os.IsNotExist(err) {
39 if err := os.MkdirAll(filepath.Dir(filename), 0600); err != nil {
40 logMessage(LOG_ERROR, "[ERROR] Failed to create pcap file: ", err.Error())
41 return
42 }
43 }
44
45 f, err := os.Create(filename)
46 if err != nil {
47 logMessage(LOG_ERROR, "[ERROR] Failed to create pcap file: ", err.Error())
48 return
49 }
50 defer f.Close()
51
52 // listening for all interfaces
53 for _, iface := range ifaces {
54 if err := CaptureInterface(&iface, &devices, bpffilter, f, verbose); err != nil && verbose {
55 logMessage(LOG_ERROR, "[ERROR]", err)
56 }
57 }
58}
59
60// CaptureInterface dump all packet on specified network interface
61func CaptureInterface(iface *net.Interface, devices *[]pcap.Interface, bpffilter string, f *os.File, verbose bool) error {

Callers 1

mainFunction · 0.85

Calls 2

logMessageFunction · 0.85
CaptureInterfaceFunction · 0.85

Tested by

no test coverage detected