types.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package tools
  2. type PingRequest struct {
  3. Target string `json:"target"`
  4. Count int `json:"count"` // 1 - 20, default 4
  5. Size int `json:"size"` // default 56
  6. Interface string `json:"interface"` // optional source interface
  7. Timeout int `json:"timeout"` // seconds, default 5
  8. DoNotFrag bool `json:"dont_frag"`
  9. }
  10. type PingReply struct {
  11. Seq int `json:"seq"`
  12. Bytes int `json:"bytes"`
  13. From string `json:"from"`
  14. TTL int `json:"ttl"`
  15. TimeMs float64 `json:"time_ms"`
  16. }
  17. type PingResponse struct {
  18. Target string `json:"target"`
  19. PacketsSent int `json:"packets_sent"`
  20. PacketsRecv int `json:"packets_recv"`
  21. PacketLossPct float64 `json:"packet_loss_pct"`
  22. MinRTT float64 `json:"min_rtt_ms"`
  23. AvgRTT float64 `json:"avg_rtt_ms"`
  24. MaxRTT float64 `json:"max_rtt_ms"`
  25. MdevRTT float64 `json:"mdev_rtt_ms"`
  26. Replies []PingReply `json:"replies"`
  27. RawOutput string `json:"raw_output"`
  28. Status string `json:"status"` // "ok", "partial", "timeout", "error"
  29. Error string `json:"error,omitempty"`
  30. }
  31. type TracerouteRequest struct {
  32. Target string `json:"target"`
  33. MaxHops int `json:"max_hops"` // default 15, max 30
  34. Resolve bool `json:"resolve"` // DNS resolve IPs
  35. Interface string `json:"interface"` // source dev
  36. Protocol string `json:"protocol"` // "icmp", "udp"
  37. }
  38. type TracerouteHop struct {
  39. Hop int `json:"hop"`
  40. Host string `json:"host"`
  41. IP string `json:"ip"`
  42. TimesMs []string `json:"times_ms"`
  43. Status string `json:"status"` // "ok", "timeout"
  44. }
  45. type TracerouteResponse struct {
  46. Target string `json:"target"`
  47. Hops []TracerouteHop `json:"hops"`
  48. RawOutput string `json:"raw_output"`
  49. Error string `json:"error,omitempty"`
  50. }
  51. type DNSRequest struct {
  52. Domain string `json:"domain"`
  53. Type string `json:"type"` // A, AAAA, MX, TXT, NS, CNAME, ANY
  54. Server string `json:"server"` // optional DNS server IP
  55. }
  56. type DNSRecord struct {
  57. Name string `json:"name"`
  58. TTL int `json:"ttl"`
  59. Class string `json:"class"`
  60. Type string `json:"type"`
  61. Value string `json:"value"`
  62. }
  63. type DNSResponse struct {
  64. Domain string `json:"domain"`
  65. Type string `json:"type"`
  66. Server string `json:"server"`
  67. QueryTimeMs int `json:"query_time_ms"`
  68. Records []DNSRecord `json:"records"`
  69. RawOutput string `json:"raw_output"`
  70. Error string `json:"error,omitempty"`
  71. }
  72. type PortProbeRequest struct {
  73. Target string `json:"target"`
  74. Port int `json:"port"`
  75. Timeout int `json:"timeout"` // default 2s
  76. }
  77. type PortProbeResponse struct {
  78. Target string `json:"target"`
  79. Port int `json:"port"`
  80. Open bool `json:"open"`
  81. LatencyMs float64 `json:"latency_ms"`
  82. Service string `json:"service,omitempty"`
  83. RawOutput string `json:"raw_output"`
  84. Error string `json:"error,omitempty"`
  85. }
  86. type MTRRequest struct {
  87. Target string `json:"target"`
  88. Count int `json:"count"` // default 3
  89. }
  90. type MTRHop struct {
  91. Hop int `json:"hop"`
  92. Host string `json:"host"`
  93. LossPct float64 `json:"loss_pct"`
  94. Sent int `json:"sent"`
  95. LastMs float64 `json:"last_ms"`
  96. AvgMs float64 `json:"avg_ms"`
  97. BestMs float64 `json:"best_ms"`
  98. WrstMs float64 `json:"wrst_ms"`
  99. StDevMs float64 `json:"stdev_ms"`
  100. }
  101. type MTRResponse struct {
  102. Target string `json:"target"`
  103. Hops []MTRHop `json:"hops"`
  104. RawOutput string `json:"raw_output"`
  105. Error string `json:"error,omitempty"`
  106. }