net

package
v0.0.0-...-39cffea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ping

func Ping(ctx context.Context, ips []string, opts ...Option) (map[string]Status, error)

Ping do ping

Example
package main

import (
	"context"
	"log"
	"time"

	"github.com/leopoldxx/go-utils/net"
)

func main() {
	targetIP := []string{
		"8.8.8.8",
		"1.1.1.1",
		"2.2.2.2",
		"61.135.169.121",
		"61.135.157.156",
		"123.126.104.68",
		"211.144.7.85",
	}

	log.SetFlags(log.Lmicroseconds | log.LstdFlags)
	log.Printf("ping")
	res, err := net.Ping(context.TODO(), targetIP, net.WithTTL(time.Millisecond*800))
	if err != nil {
		log.Printf("ping failed: %s", err)
		return
	}
	for ip, status := range res {
		log.Printf("%s is %s, %v", ip, func(status net.Status) string {
			if status.OK == true {
				return "ok"
			}
			return "unreachable"
		}(status), status.RTT)
	}
}
Output:

Types

type Option

type Option func(opt *option)

func WithTTL

func WithTTL(ttl time.Duration) Option

type Status

type Status struct {
	OK  bool
	RTT time.Duration
}

Status of the target host

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL