Skip to content

Instantly share code, notes, and snippets.

@inuoshios
Last active January 1, 2022 18:18
Show Gist options
  • Save inuoshios/1317bbbb29f19906e11a4899baa99692 to your computer and use it in GitHub Desktop.
Save inuoshios/1317bbbb29f19906e11a4899baa99692 to your computer and use it in GitHub Desktop.
Created this little Golang "script, maybe" to lookup the IP Address Not perfect, but yeah!
package main
import (
"flag"
"fmt"
"net"
"os"
)
var ip string
func init() {
flag.StringVar(&ip, "ip", "", "Checks for ip address")
f := flag.Flag{
Name: "John-IP",
Usage: "go run [filename.go] -ip [command]",
DefValue: "Looks up the IP Address - ",
}
fmt.Printf("NAME:\n \t %s \nUSAGE:\n \t %s \nOUTPUT: \n \t %s", f.Name, f.Usage, f.DefValue) // printing out the formatted strings
}
func main() {
flag.Parse()
// Still the same as using your if statement
switch ip {
case "yes":
ip, err := net.LookupIP("localhost")
if err != nil {
fmt.Println(err.Error())
}
for i := range ip {
fmt.Println(ip[i])
}
case "no":
fmt.Println("Sorry, you picked no!")
os.Exit(1)
}
}
@inuoshios
Copy link
Author

Will be updating it from time to time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment