Skip to content

Instantly share code, notes, and snippets.

@irom77
Forked from ekoecho/TCP Check
Created December 8, 2016 00:42
Show Gist options
  • Save irom77/f27a0f475c3217034196562bbe8cf344 to your computer and use it in GitHub Desktop.
Save irom77/f27a0f475c3217034196562bbe8cf344 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net"
)
func main() {
var status string
conn, err := net.Dial("tcp", "127.0.0.1:80")
if err != nil {
log.Println("Connection error:", err)
status = "Unreachable"
} else {
status = "Online"
defer conn.Close()
}
log.Println(status)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment