Skip to content

Instantly share code, notes, and snippets.

@clone1018
Created November 1, 2013 16:02
Show Gist options
  • Save clone1018/7267590 to your computer and use it in GitHub Desktop.
Save clone1018/7267590 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net"
"os"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Please specify a host.")
return
}
var host string = os.Args[1]
var status bool = checkConnection(host)
if status {
fmt.Println(host + ": online")
} else {
fmt.Println(host + ": offline")
}
}
func checkConnection(host string) bool {
_, err := net.Dial("tcp", host)
if err != nil {
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment