cmd

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package cmd commands

Package cmd commands

Index

Constants

View Source
const (
	// API is the URL of ifconfig network info API
	API string = "https://ifconfig.is/json/"
)

Variables

View Source
var (
	// IPType4 is the type of IP address to use for IPv4
	IPType4 = IPType{
		Type:               "4",
		ListenAddr:         "0.0.0.0",
		Network:            "ip4",
		ICMPNetwork:        "ip4:icmp",
		ProtocolNumber:     1,
		RequestMessageType: ipv4.ICMPTypeEcho,
		ReplyMessageType:   ipv4.ICMPTypeEchoReply,
	}
	// IPType6 is the type of IP address to use for IPv6
	IPType6 = IPType{
		Type:               "6",
		ListenAddr:         "::",
		Network:            "ip6",
		ICMPNetwork:        "ip6:ipv6-icmp",
		ProtocolNumber:     58,
		RequestMessageType: ipv6.ICMPTypeEchoRequest,
		ReplyMessageType:   ipv6.ICMPTypeEchoReply,
	}
)
View Source
var (
	Name    = configName
	Version = "- not set -"
	Commit  = "snapshot"
	Date    = ""
)

Version, Build Commit and Date are filled in during build by the Makefile noinspection GoUnusedGlobalVariable

View Source
var (
	QueryCmd = &cobra.Command{
		Use:          "query",
		Short:        "Query host ip information",
		Long:         ``,
		RunE:         runQuery,
		SilenceUsage: true,
	}
)
View Source
var (
	// RootCmd function to execute in tests
	RootCmd = &cobra.Command{
		Use:   "tcping2",
		Short: "tcping2 – open port probe and ip info command line tool, supporting ICMP, TCP and HTTP protocols",
		Long: `Tcping2 is a ip probe command line tool, supporting ICMP and TCP protocols 
      It may also run an httptrace and ip traces (using system mtr installation).
      You can also use it to query IP network information from https://ifconfig.is.
      it has an echo server and client function to check not yet available service ports`,
	}
)

Functions

func Execute

func Execute()

Execute run application

func GetVersion

func GetVersion(print bool) (txt string)

GetVersion extract compiled version info

Types

type DescMTR

type DescMTR struct {
	Src        string `json:"src"`
	Dst        string `json:"dst"`
	Tos        int    `json:"tos"`
	Tests      int    `json:"tests"`
	Psize      string `json:"psize"`
	Bitpattern string `json:"bitpattern"`
}

DescMTR is a struct that contains the MTR call information

type HTTPing

type HTTPing struct {
	URL      string
	Proxy    bool
	Scheme   string
	DNS      int64
	TCP      int64
	TLS      int64
	Process  int64
	Transfer int64
	Total    int64
}

HTTPing is a struct that contains the statistics of the httping

func (*HTTPing) Log

func (h *HTTPing) Log()

Log logs the httping results

func (*HTTPing) Run

func (h *HTTPing) Run(address string) (err error)

Run New sends an HTTP request to a given address and returns the time it took to get a reply

type HopsMTR

type HopsMTR struct {
	Count int     `json:"count"`
	Host  string  `json:"host"`
	Loss  float64 `json:"Loss%"`
	Snt   int     `json:"Snt"`
	Last  float64 `json:"Last"`
	Avg   float64 `json:"Avg"`
	Best  float64 `json:"Best"`
	Wrst  float64 `json:"Wrst"`
	StDev float64 `json:"StDev"`
}

HopsMTR is a struct that contains the MTR hop information

type ICMPing

type ICMPing struct {
	Address  string
	IP       *net.IPAddr
	Duration time.Duration
	IPType   IPType
}

func (*ICMPing) Log

func (i *ICMPing) Log(err error)

Log logs the ping results

func (*ICMPing) Run

func (i *ICMPing) Run(host string) (err error)

Run sends an ICMP echo request to a given address and returns the time it took to get a reply

type IPInfo

type IPInfo struct {
	IP        string
	Continent string  `json:"Continent"`
	Country   string  `json:"Country"`
	City      string  `json:"City"`
	Latitude  float64 `json:"Latitude"`
	Longitude float64 `json:"Longitude"`
	TimeZone  string  `json:"TimeZone"`
	ASN       uint    `json:"ASN"`
	ORG       string  `json:"Organization"`
}

IPInfo is the struct of IP information

func QueryInfo

func QueryInfo(address string) (info IPInfo, err error)

QueryInfo queries the IP information

type IPType

type IPType struct {
	Type               string
	ListenAddr         string
	Network            string
	ICMPNetwork        string
	ProtocolNumber     int
	RequestMessageType icmp.Type
	ReplyMessageType   icmp.Type
}

IPType is a struct that contains the type of IP address to use

type MTR

type MTR struct {
	Report ReportMTR `json:"report"`
}

MTR is a struct that contains the MTR report

func (*MTR) Log

func (mtr *MTR) Log()

Log logs the mtr results

func (*MTR) Parse

func (mtr *MTR) Parse(b []byte) (hops []HopsMTR, err error)

func (*MTR) Run

func (mtr *MTR) Run(ip string, port string, t bool) (err error)

Run runs system mtr command and returns the IP addresses of the hops

type ReportMTR

type ReportMTR struct {
	Desc DescMTR   `json:"mtr"`
	Hops []HopsMTR `json:"hubs"`
}

ReportMTR is a struct that contains the MTR report parts

type TCPing

type TCPing struct {
	Address string
	Msg     string
	Code    int
}

func (*TCPing) Log

func (t *TCPing) Log()

Log logs the tcping results

func (*TCPing) Run

func (t *TCPing) Run(address string) (msg string)

Run sends a TCP request to a given address and returns the status of the connection

Jump to

Keyboard shortcuts

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