Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import (
- "fmt"
- "github.com/urfave/cli"
- "log"
- "net"
- "os"
- )
- func main() {
- app := cli.NewApp()
- app.Name = "Website Lookup CLI"
- app.Usage = "Let's you query IPs, CNAMEs, MX records and Name Servers!"
- app.Version = "1.0.0"
- app.Author = "Adeshina H. H."
- // We'll be using the same flag for all our commands
- // so we'll define it up here
- myFlags := []cli.Flag{
- cli.StringFlag{
- Name: "host",
- Value: "tutorialedge.net",
- },
- }
- // we create our commands
- app.Commands = []cli.Command{
- {
- Name: "ns",
- Usage: "Looks Up the NameServers for a Particular Host",
- Flags: myFlags,
- // the action, or code that will be executed when
- // we execute our `ns` command
- Action: func(c *cli.Context) error {
- // a simple lookup function
- ns, err := net.LookupNS(c.String("url"))
- if err != nil {
- return err
- }
- // we log the results to our console
- // using a trusty fmt.Println statement
- for i := 0; i < len(ns); i++ {
- fmt.Println(ns[i].Host)
- }
- return nil
- },
- },
- }
- // start our application
- err := app.Run(os.Args)
- if err != nil {
- log.Fatal(err)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement