ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Other languages

check-host api GOLANG

Submitted by 1926 at 01-02-2025, 08:39 PM


check-host api GOLANG
669 Views
1926's Avatar'
1926
Offline
#1
[ Hidden Content! ]
package main

import (
"fmt"
"os"
"time"
"net/http"
"io/ioutil"
"encoding/json"
)

type Result struct {
RequestID string `json:"request_id"`
}

func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: paping <IP_or_Domain> <Port>")
return
}

host := os.Args[1]
port := os.Args[2]

fmt.Println("Waiting for 10 seconds before starting the ping test...")
time.Sleep(10 * time.Second)

url := fmt.Sprintf("https://check-host.net/check-ping?host=%s&max_nodes=5", host)
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error during request:", err)
return
}
defer resp.Body.Close()

body, _ := ioutil.ReadAll(resp.Body)

var result Result
err = json.Unmarshal(body, &result)
if err != nil {
fmt.Println("Error parsing JSON:", err)
return
}

reportLink := fmt.Sprintf("https://check-host.net/check-result/%s", result.RequestID)
fmt.Printf("Ping results are available at: %s\n", reportLink)
}
0
Reply


Messages In This Thread
check-host api GOLANG - by 1926 - 01-02-2025, 08:39 PM
RE: check-host api GOLANG - by lendore - 01-02-2025, 10:06 PM
RE: check-host api GOLANG - by wolfrizon11 - 03-02-2025, 04:46 PM
RE: check-host api GOLANG - by codxx - 10-02-2025, 11:50 PM


Users browsing this thread: 1 Guest(s)