File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ package main
33import (
44 "flag"
55 "fmt"
6+ "net"
7+ "os"
8+ "strings"
69
710 ms "github.com/shadowy-pycoder/mshark"
811)
@@ -27,6 +30,18 @@ Options:
2730 -h Show this help message and exit.
2831`
2932
33+ func displayInterfaces () error {
34+ ifaces , err := net .Interfaces ()
35+ if err != nil {
36+ return fmt .Errorf ("failed to get network interfaces: %v" , err )
37+ }
38+ fmt .Println ("0. any" )
39+ for _ , iface := range ifaces {
40+ fmt .Printf ("%d. %s %s\n " , iface .Index , iface .Name , strings .ToUpper (iface .Flags .String ()))
41+ }
42+ return nil
43+ }
44+
3045func root (args []string ) error {
3146 conf := ms.Config {}
3247
@@ -46,6 +61,14 @@ func root(args []string) error {
4661 return nil
4762 })
4863 flags .StringVar (& conf .PcapPath , "path" , "" , "Path to a PCAP file. Example: ./captured.pcap" )
64+ flags .BoolFunc ("D" , "Display list of interfaces and exit." , func (flagValue string ) error {
65+ if err := displayInterfaces (); err != nil {
66+ fmt .Fprintf (os .Stderr , "mshark: %v\n " , err )
67+ os .Exit (2 )
68+ }
69+ os .Exit (0 )
70+ return nil
71+ })
4972
5073 flags .Usage = func () {
5174 fmt .Print (usagePrefix )
You can’t perform that action at this time.
0 commit comments