Advertisement
Guest User

go script

a guest
Aug 19th, 2018
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.95 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "os/exec"
  6.     "runtime"
  7. )
  8.  
  9. func execute() {
  10.  
  11.   // here we perform the pwd command.
  12.   // we can store the output of this in our out variable
  13.   // and catch any errors in err
  14.     out, err := exec.Command("tshark", "-i", "em1").CombinedOutput()
  15.  
  16.   // if there is an error with our execution
  17.   // handle it here
  18.     if err != nil {
  19.         fmt.Printf("%s", err)
  20.     }
  21.  
  22.     fmt.Println("Command Successfully Executed")
  23.   // as the out variable defined above is of type []byte we need to convert
  24.   // this to a string or else we will see garbage printed out in our console
  25.   // this is how we convert it to a string
  26.     output := string(out[:])
  27.  
  28.   // once we have converted it to a string we can then output it.
  29.     fmt.Println(output)
  30. }
  31.  
  32. func main() {
  33.  
  34.     fmt.Println("Simple Shell")
  35.     fmt.Println("---------------------")
  36.  
  37.     if runtime.GOOS == "windows" {
  38.         fmt.Println("Can't Execute this on a windows machine")
  39.     } else {
  40.         execute()
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement