Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import (
  2. "fmt"
  3. "github.com/urfave/cli"
  4. "log"
  5. "net"
  6. "os"
  7. )
  8.  
  9.  
  10. func main() {
  11.  
  12. app := cli.NewApp()
  13. app.Name = "Website Lookup CLI"
  14. app.Usage = "Let's you query IPs, CNAMEs, MX records and Name Servers!"
  15. app.Version = "1.0.0"
  16. app.Author = "Adeshina H. H."
  17.  
  18. // We'll be using the same flag for all our commands
  19. // so we'll define it up here
  20. myFlags := []cli.Flag{
  21. cli.StringFlag{
  22. Name: "host",
  23. Value: "tutorialedge.net",
  24. },
  25. }
  26.  
  27. // we create our commands
  28. app.Commands = []cli.Command{
  29. {
  30. Name: "ns",
  31. Usage: "Looks Up the NameServers for a Particular Host",
  32. Flags: myFlags,
  33. // the action, or code that will be executed when
  34. // we execute our `ns` command
  35. Action: func(c *cli.Context) error {
  36. // a simple lookup function
  37. ns, err := net.LookupNS(c.String("url"))
  38. if err != nil {
  39. return err
  40. }
  41. // we log the results to our console
  42. // using a trusty fmt.Println statement
  43. for i := 0; i < len(ns); i++ {
  44. fmt.Println(ns[i].Host)
  45. }
  46. return nil
  47. },
  48. },
  49.  
  50.  
  51. }
  52.  
  53.  
  54. // start our application
  55. err := app.Run(os.Args)
  56. if err != nil {
  57. log.Fatal(err)
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement