back to listing index

Running Wireshark on Docker – Tapan Chugh – Medium

[web search]
Original source (medium.com)
Tags: containers golang go docker wireshark ethereal
Clipped on: 2017-03-29

Image (Asset 1/6) alt= “os”
“fmt”
“net”
“runtime”
“github.com/vishvananda/netns”
“os/exec”
)
func main() {
// Lock the OS Thread so we don’t accidentally switch namespaces
runtime.LockOSThread()
defer runtime.UnlockOSThread()
// Save the current network namespace
origns, _ := netns.Get()
defer origns.Close()
// Get the network namespace based on container id
newns, _ := netns.GetFromDocker(“a115e93f5137”)
defer newns.Close()
netns.Set(newns)
// Do something with the network namespace
ifaces, _ := net.Interfaces()
fmt.Printf(“Interfaces: %v\n”, ifaces)
cmd := exec.Command(“tshark”,”-z”,”conv,ip”,”-i”,”eth0")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Run()
 //Return to original namespace
`netns.Set(origns)
}

This program must be run as root since it changes the network namespace. Instead of using wireshark, i used the command line version tshark, and run it in the conversation mode. This can be changed according to the needs.