Skip to content

Instantly share code, notes, and snippets.

@pyk
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyk/41ec9725ebee05370e58 to your computer and use it in GitHub Desktop.
Save pyk/41ec9725ebee05370e58 to your computer and use it in GitHub Desktop.
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)
}
$ 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