Last active
January 1, 2022 18:18
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will be updating it from time to time. ✔