Last active
August 29, 2015 14:01
-
-
Save pyk/41ec9725ebee05370e58 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"net" | |
"os" | |
"fmt" | |
) | |
func main() { | |
// if script running without argument, give usage information | |
if len(os.Args) != 2 { | |
fmt.Fprintf(os.Stderr, "Usage: %s hostname\n", os.Args[0]) | |
fmt.Println("Usage: ", os.Args[0], "hostname") | |
os.Exit(1) | |
} | |
// Process given argument host name | |
name := os.Args[1] | |
addr, err := net.ResolveIPAddr("ip", name) | |
if err != nil { | |
fmt.Println("Resolution error", err.Error()) | |
os.Exit(1) | |
} | |
fmt.Fprintf("Resolved address for %s is %s \n", name, addr.String()) | |
os.Exit(0) | |
} |
This file contains hidden or 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
$ go build resolve.go | |
$ ./resolve www.hostname.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment