Created
November 1, 2013 16:02
-
-
Save clone1018/7267590 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 ( | |
"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