libf 2 anni fa
parent
commit
65b065243e

+ 187 - 1
ping/hosts.last.txt

@@ -535,4 +535,190 @@ weiyun.com,weibo.com,189.cn,jianguoyun.com
 223.239.35.47,52.203.146.60,144.48.222.108
 24.119.185.21
 98.49.232.177
-15.188.60.176
+15.188.60.176
+67.168.52.89
+98.226.86.9
+72.210.77.116
+72.227.187.109
+119.97.219.182
+187.175.57.213
+67.158.170.238
+107.185.115.102
+14.85.126.231
+116.14.14.23
+74.76.90.28
+92.32.152.60
+194.193.57.101
+150.138.79.151
+77.127.27.83
+218.49.38.83,176.85.116.237
+201.35.186.149
+216.2.232.193
+5.145.226.122
+87.57.105.67
+23.226.221.223
+146.70.27.242
+97.104.72.233
+118.43.79.147
+195.9.72.60
+40.134.95.36
+67.205.182.31
+24.216.219.49
+123.181.77.152
+117.159.99.201
+1.44.113.186
+76.74.53.46
+41.27.193.52
+177.7.89.18,90.215.85.61
+121.158.41.131
+178.187.246.98,5.55.251.39
+54.241.49.128
+207.32.20.13
+73.176.65.202
+112.145.180.49
+196.183.67.27
+76.22.115.171
+175.98.219.26
+1.63.71.110
+1.247.156.156
+174.172.92.195
+103.113.163.150
+50.238.77.243,87.2.106.161
+149.241.240.129
+104.20.59.125
+201.103.223.118
+104.118.228.53,86.127.152.161,86.14.171.123,187.195.138.253
+209.107.188.150
+47.150.208.42
+88.25.52.251
+222.65.196.129
+1.252.142.138
+199.7.205.110
+197.205.26.90
+212.54.63.5,85.1.252.129
+124.64.91.181
+73.32.253.59
+123.131.10.39
+221.165.124.77
+88.94.77.246
+50.32.183.200
+81.100.36.145
+58.42.21.92
+117.14.235.64
+81.83.207.199
+103.42.165.1
+103.144.224.34
+171.220.227.44
+178.193.147.7,178.70.95.193
+67.175.28.197
+130.214.128.214
+203.126.172.158
+85.158.249.240
+73.82.30.131
+117.191.55.94
+120.236.235.25
+186.55.88.98
+45.63.90.67
+182.124.31.80
+82.32.166.252
+175.202.188.88
+82.2.133.5
+47.92.137.122
+72.247.20.236
+76.167.87.15
+98.51.235.40
+217.86.98.150
+95.119.188.72
+73.117.112.149
+83.76.232.142
+73.136.134.15,201.200.140.168
+172.83.155.204
+98.198.149.101,78.18.250.222
+31.217.241.6
+115.13.62.154
+73.119.71.180
+13.32.171.61
+50.54.84.9
+23.87.93.118
+120.28.22.5,36.4.146.161
+175.233.82.98
+100.35.140.98
+211.232.4.129,121.174.15.39
+88.20.1.187
+149.72.227.22
+179.34.12.190
+58.153.198.236
+209.105.173.129
+93.214.39.239
+67.189.199.223,52.53.174.220
+89.10.34.52,88.27.195.147
+218.93.94.193,80.6.220.168
+124.31.41.84
+76.97.162.231
+107.167.11.249
+159.223.116.93
+82.42.132.51
+96.232.130.147,62.252.30.137
+121.227.140.53
+75.68.63.203
+212.91.24.61
+123.135.219.189
+212.233.13.222
+112.133.57.55
+112.140.115.233
+73.117.112.118,202.37.168.49,187.181.161.112
+110.6.71.33
+187.193.203.108
+125.38.218.177
+82.37.42.199
+213.226.62.119,176.20.155.253
+49.238.23.170
+114.239.36.68,117.193.48.204
+98.187.131.228,38.135.201.132
+101.206.108.34
+49.1.105.13
+2.203.60.231
+154.215.189.118
+71.231.243.171,207.148.121.182
+24.239.248.223,118.44.140.246,151.224.59.162
+196.46.24.99
+72.4.36.23,46.142.163.37
+72.205.43.35
+45.33.236.230,223.151.75.247
+23.242.97.35
+189.237.104.164
+73.250.43.249,73.208.2.22,78.34.128.73
+98.144.55.165,93.201.56.183,68.150.221.28
+24.250.44.147,87.48.51.16,60.101.174.125
+107.4.232.171,36.7.207.81,212.53.160.142
+119.114.35.26
+187.13.12.124,178.119.112.76,39.120.79.170,67.246.245.240
+84.162.86.116,59.13.223.31,1.224.142.102,2.206.235.10,75.75.134.163,162.222.199.184
+221.195.134.85,180.246.118.147
+201.123.18.37,49.75.94.118,174.58.53.181,72.239.103.171
+2.216.186.190,114.244.1.221,83.12.177.133,173.25.124.114,177.51.156.213,195.182.13.176,176.105.109.234,170.233.140.250,96.225.48.46,201.146.184.219,78.34.118.37,60.73.42.142
+175.239.130.76,60.117.132.194,108.175.207.223,54.166.171.233
+89.38.12.107,180.233.226.109,179.223.239.171,124.51.43.48
+223.229.187.71,83.34.119.146,73.159.6.89,134.56.214.9,83.171.164.80
+109.8.250.91,36.251.43.191,106.14.39.34,173.33.58.138,173.70.199.34,118.221.150.18,95.157.166.10,95.64.211.113,210.92.69.65,60.126.50.173
+23.35.207.100,89.117.94.36,76.171.162.139
+83.51.232.58,115.53.197.109,97.113.136.154,155.94.181.86,220.70.233.62,139.209.137.46
+118.208.116.38,69.245.9.41,2.106.17.103,185.162.54.105,72.205.108.20,126.79.233.149,180.156.6.147,72.215.254.230,95.212.140.224
+76.114.66.129,220.121.2.226,98.169.8.112,59.19.163.173,102.30.89.63,201.248.215.12,173.69.156.44,46.55.171.49
+200.10.132.221,211.184.237.198,182.243.152.82,212.186.89.229,112.144.70.241
+93.126.78.121,216.83.45.152,125.142.51.99
+58.127.224.145,82.10.58.139,95.56.219.248,89.10.78.107,175.195.209.139,2.181.47.133
+24.201.191.34,178.8.254.239,136.53.17.189,211.192.159.66,51.219.216.112,60.111.246.108
+72.196.27.146,51.83.14.65,74.111.105.17,69.142.126.80,190.231.15.200,65.254.146.73
+194.60.248.33,189.167.25.99,187.132.88.60,98.2.214.190
+71.233.180.241,112.168.208.192
+73.225.111.238,221.162.15.218,179.126.74.106,66.130.186.194,185.33.234.117,106.68.180.134,121.167.51.179,82.157.21.20,119.112.20.146,52.31.157.138
+67.186.187.11,210.113.108.5,62.2.111.81,75.117.200.30,136.57.217.84,14.169.129.166,174.18.68.55
+88.151.197.33,123.120.109.16,73.99.104.204,174.56.215.45
+192.40.170.103,71.244.202.31,1.116.131.225,106.197.121.3,126.91.163.192,182.188.194.4,46.48.205.224,2.62.47.113,217.87.122.249,114.227.30.35,37.116.86.67,90.176.218.222
+184.82.25.45,81.12.77.230,94.43.83.168,75.31.78.212,113.239.219.161,79.219.3.61,130.164.160.89
+186.7.43.136
+192.104.115.30,88.77.102.254,68.202.200.105,39.88.74.66,14.89.19.240,76.28.64.121,83.53.250.93,171.218.158.231,61.137.246.116
+176.253.168.43,171.110.239.133,125.154.21.109,156.224.236.74,119.130.131.153,105.102.198.108,31.148.242.10,105.133.166.117,182.121.250.64,207.204.17.124
+113.231.150.46,219.115.13.58,69.242.201.25
+61.81.140.176,187.170.19.21,177.36.47.64,81.170.9.30,110.8.197.30,46.10.59.130,180.64.179.179,78.197.124.132,202.86.159.249

+ 187 - 1
ping/hosts.txt

@@ -536,4 +536,190 @@ weiyun.com,weibo.com,189.cn,jianguoyun.com
 24.119.185.21
 98.49.232.177
 15.188.60.176
-67.168.52.89
+67.168.52.89
+98.226.86.9
+72.210.77.116
+72.227.187.109
+119.97.219.182
+187.175.57.213
+67.158.170.238
+107.185.115.102
+14.85.126.231
+116.14.14.23
+74.76.90.28
+92.32.152.60
+194.193.57.101
+150.138.79.151
+77.127.27.83
+218.49.38.83,176.85.116.237
+201.35.186.149
+216.2.232.193
+5.145.226.122
+87.57.105.67
+23.226.221.223
+146.70.27.242
+97.104.72.233
+118.43.79.147
+195.9.72.60
+40.134.95.36
+67.205.182.31
+24.216.219.49
+123.181.77.152
+117.159.99.201
+1.44.113.186
+76.74.53.46
+41.27.193.52
+177.7.89.18,90.215.85.61
+121.158.41.131
+178.187.246.98,5.55.251.39
+54.241.49.128
+207.32.20.13
+73.176.65.202
+112.145.180.49
+196.183.67.27
+76.22.115.171
+175.98.219.26
+1.63.71.110
+1.247.156.156
+174.172.92.195
+103.113.163.150
+50.238.77.243,87.2.106.161
+149.241.240.129
+104.20.59.125
+201.103.223.118
+104.118.228.53,86.127.152.161,86.14.171.123,187.195.138.253
+209.107.188.150
+47.150.208.42
+88.25.52.251
+222.65.196.129
+1.252.142.138
+199.7.205.110
+197.205.26.90
+212.54.63.5,85.1.252.129
+124.64.91.181
+73.32.253.59
+123.131.10.39
+221.165.124.77
+88.94.77.246
+50.32.183.200
+81.100.36.145
+58.42.21.92
+117.14.235.64
+81.83.207.199
+103.42.165.1
+103.144.224.34
+171.220.227.44
+178.193.147.7,178.70.95.193
+67.175.28.197
+130.214.128.214
+203.126.172.158
+85.158.249.240
+73.82.30.131
+117.191.55.94
+120.236.235.25
+186.55.88.98
+45.63.90.67
+182.124.31.80
+82.32.166.252
+175.202.188.88
+82.2.133.5
+47.92.137.122
+72.247.20.236
+76.167.87.15
+98.51.235.40
+217.86.98.150
+95.119.188.72
+73.117.112.149
+83.76.232.142
+73.136.134.15,201.200.140.168
+172.83.155.204
+98.198.149.101,78.18.250.222
+31.217.241.6
+115.13.62.154
+73.119.71.180
+13.32.171.61
+50.54.84.9
+23.87.93.118
+120.28.22.5,36.4.146.161
+175.233.82.98
+100.35.140.98
+211.232.4.129,121.174.15.39
+88.20.1.187
+149.72.227.22
+179.34.12.190
+58.153.198.236
+209.105.173.129
+93.214.39.239
+67.189.199.223,52.53.174.220
+89.10.34.52,88.27.195.147
+218.93.94.193,80.6.220.168
+124.31.41.84
+76.97.162.231
+107.167.11.249
+159.223.116.93
+82.42.132.51
+96.232.130.147,62.252.30.137
+121.227.140.53
+75.68.63.203
+212.91.24.61
+123.135.219.189
+212.233.13.222
+112.133.57.55
+112.140.115.233
+73.117.112.118,202.37.168.49,187.181.161.112
+110.6.71.33
+187.193.203.108
+125.38.218.177
+82.37.42.199
+213.226.62.119,176.20.155.253
+49.238.23.170
+114.239.36.68,117.193.48.204
+98.187.131.228,38.135.201.132
+101.206.108.34
+49.1.105.13
+2.203.60.231
+154.215.189.118
+71.231.243.171,207.148.121.182
+24.239.248.223,118.44.140.246,151.224.59.162
+196.46.24.99
+72.4.36.23,46.142.163.37
+72.205.43.35
+45.33.236.230,223.151.75.247
+23.242.97.35
+189.237.104.164
+73.250.43.249,73.208.2.22,78.34.128.73
+98.144.55.165,93.201.56.183,68.150.221.28
+24.250.44.147,87.48.51.16,60.101.174.125
+107.4.232.171,36.7.207.81,212.53.160.142
+119.114.35.26
+187.13.12.124,178.119.112.76,39.120.79.170,67.246.245.240
+84.162.86.116,59.13.223.31,1.224.142.102,2.206.235.10,75.75.134.163,162.222.199.184
+221.195.134.85,180.246.118.147
+201.123.18.37,49.75.94.118,174.58.53.181,72.239.103.171
+2.216.186.190,114.244.1.221,83.12.177.133,173.25.124.114,177.51.156.213,195.182.13.176,176.105.109.234,170.233.140.250,96.225.48.46,201.146.184.219,78.34.118.37,60.73.42.142
+175.239.130.76,60.117.132.194,108.175.207.223,54.166.171.233
+89.38.12.107,180.233.226.109,179.223.239.171,124.51.43.48
+223.229.187.71,83.34.119.146,73.159.6.89,134.56.214.9,83.171.164.80
+109.8.250.91,36.251.43.191,106.14.39.34,173.33.58.138,173.70.199.34,118.221.150.18,95.157.166.10,95.64.211.113,210.92.69.65,60.126.50.173
+23.35.207.100,89.117.94.36,76.171.162.139
+83.51.232.58,115.53.197.109,97.113.136.154,155.94.181.86,220.70.233.62,139.209.137.46
+118.208.116.38,69.245.9.41,2.106.17.103,185.162.54.105,72.205.108.20,126.79.233.149,180.156.6.147,72.215.254.230,95.212.140.224
+76.114.66.129,220.121.2.226,98.169.8.112,59.19.163.173,102.30.89.63,201.248.215.12,173.69.156.44,46.55.171.49
+200.10.132.221,211.184.237.198,182.243.152.82,212.186.89.229,112.144.70.241
+93.126.78.121,216.83.45.152,125.142.51.99
+58.127.224.145,82.10.58.139,95.56.219.248,89.10.78.107,175.195.209.139,2.181.47.133
+24.201.191.34,178.8.254.239,136.53.17.189,211.192.159.66,51.219.216.112,60.111.246.108
+72.196.27.146,51.83.14.65,74.111.105.17,69.142.126.80,190.231.15.200,65.254.146.73
+194.60.248.33,189.167.25.99,187.132.88.60,98.2.214.190
+71.233.180.241,112.168.208.192
+73.225.111.238,221.162.15.218,179.126.74.106,66.130.186.194,185.33.234.117,106.68.180.134,121.167.51.179,82.157.21.20,119.112.20.146,52.31.157.138
+67.186.187.11,210.113.108.5,62.2.111.81,75.117.200.30,136.57.217.84,14.169.129.166,174.18.68.55
+88.151.197.33,123.120.109.16,73.99.104.204,174.56.215.45
+192.40.170.103,71.244.202.31,1.116.131.225,106.197.121.3,126.91.163.192,182.188.194.4,46.48.205.224,2.62.47.113,217.87.122.249,114.227.30.35,37.116.86.67,90.176.218.222
+184.82.25.45,81.12.77.230,94.43.83.168,75.31.78.212,113.239.219.161,79.219.3.61,130.164.160.89
+186.7.43.136
+192.104.115.30,88.77.102.254,68.202.200.105,39.88.74.66,14.89.19.240,76.28.64.121,83.53.250.93,171.218.158.231,61.137.246.116
+176.253.168.43,171.110.239.133,125.154.21.109,156.224.236.74,119.130.131.153,105.102.198.108,31.148.242.10,105.133.166.117,182.121.250.64,207.204.17.124
+113.231.150.46,219.115.13.58,69.242.201.25
+61.81.140.176,187.170.19.21,177.36.47.64,81.170.9.30,110.8.197.30,46.10.59.130,180.64.179.179,78.197.124.132,202.86.159.249
+67.42.81.246,187.142.210.128,41.164.156.154,188.213.188.51,190.235.61.99,84.180.226.191,183.102.40.5,173.222.232.94,192.169.179.111

+ 33 - 18
ping/ping.go

@@ -3,6 +3,7 @@ package main
 import (
 	"encoding/json"
 	"fmt"
+	"math"
 	"math/rand"
 	"os"
 	"runtime"
@@ -16,8 +17,8 @@ import (
 	"trial/ping/probing/icmp"
 	"trial/ping/utils"
 
-	"git.wecise.com/wecise/common/logger"
 	"git.wecise.com/wecise/common/matrix/cfg"
+	"git.wecise.com/wecise/common/matrix/logger"
 	"git.wecise.com/wecise/common/matrix/util"
 	"github.com/scylladb/go-set/strset"
 )
@@ -68,9 +69,11 @@ type Input struct {
 }
 
 var mcfg = cfg.MConfig()
+var protocol = mcfg.GetString("protocol", "udp")
 
 var allipsmutex sync.Mutex
 var allips = strset.New()
+var keepipset = strset.New()
 
 /*
   poolsize=1000  同时ping的不同目标地址个数
@@ -89,6 +92,10 @@ func main() {
 		Poolsize:     1000,
 		StatInterval: 600,
 	}
+	for _, aips := range mcfg.GetStrings("keep") {
+		keepipset.Add(strings.Split(aips, ",")...)
+	}
+	keepips := keepipset.List()
 	inputcfg.Poolsize = mcfg.GetInt("poolsize", inputcfg.Poolsize)
 	if detect_interval := mcfg.GetDuration("detect", 0); detect_interval != 0 {
 		go detect(detect_interval)
@@ -107,24 +114,23 @@ func main() {
 			}
 		}
 		if len(detectips) > 0 {
+			for _, aips := range detectips {
+				allips.Add(strings.Split(aips, ",")...)
+			}
 			util.WriteFile("./hosts.txt", []byte(string(bs)+"\n"+strings.Join(detectips, ",")), true)
 			detectips = detectips[:0]
 		}
+		allips.Remove(keepips...)
 		sips := allips.List()
+		// sort.Sort(sort.Reverse(sort.StringSlice(sips)))
+		rand.Shuffle(len(sips), func(i, j int) { sips[i], sips[j] = sips[j], sips[i] })
 		allipsmutex.Unlock()
 		return sips
 	}
-	go func() {
-		t := time.NewTicker(5 * time.Second)
-		for {
-			<-t.C
-			input.ips = fips()
-		}
-	}()
-	input.ips = fips()
-	mcfg.OnChanged(func(cfg cfg.Configure) {
-		input.ips = fips()
-	})
+	input.ips = append(keepips, fips()...)
+	if protocol != "udp" && protocol != "icmp" {
+		protocol = "udp"
+	}
 	input.Init(inputcfg)
 	go input.Run()
 	go func() {
@@ -160,20 +166,21 @@ func main() {
 	for {
 		if n >= len(input.ips) {
 			n = 0
-			input.ips = append(input.ips, detectips...)
+			input.ips = fips()
 		}
 		ip := input.ips[n]
 		n++
 		//
 		ip = strings.TrimSpace(ip)
 		if ip != "" {
-			input.workChan <- &task{
+			atask := &task{
 				Server:         ip,
 				Timeout:        mcfg.GetInt("timeout", 2),
 				NumberOfPings:  mcfg.GetInt("count", 5), // 至少为2,小于2会导致不能正常结束
 				PacketInterval: mcfg.GetInt("interval", 1000),
 				PacketSize:     mcfg.GetInt("size", 64),
 			}
+			input.workChan <- atask
 		}
 		// time.Sleep(1 * time.Millisecond)
 	}
@@ -205,7 +212,15 @@ func (input *Input) Run() (err error) {
 			for t := range input.workChan {
 				wg.Add(1)
 				// Run task
-				if e := input.send(t, n); e != nil {
+				n := 1
+				if keepipset.Has(t.Server) {
+					n = math.MaxInt
+				}
+				var e error
+				for ; e == nil && n > 0; n-- {
+					e = input.send(t, n)
+				}
+				if e != nil {
 					logger.Error("Send error:", e)
 					input.ds.Send(1)
 				} else {
@@ -269,7 +284,7 @@ func (input *Input) send(t *task, workerNum int) error {
 			setcap cap_net_raw=+ep /bin/goping-binary
 			getcap /bin/goping-binary to validate
 		*/
-		pinger.SetPrivileged(false)
+		pinger.SetPrivileged(protocol == "icmp")
 		if t.NumberOfPings > 0 {
 			pinger.Count = t.NumberOfPings
 		} else {
@@ -450,9 +465,9 @@ func detectip(addr string) (ok bool) {
 	if err != nil {
 		return false
 	}
-	pinger.SetPrivileged(false)
+	pinger.SetPrivileged(protocol == "icmp")
 	pinger.Count = 1
-	pinger.Interval = 200 * time.Millisecond
+	pinger.Interval = 1 * time.Nanosecond
 	pinger.Size = 32
 	pinger.Timeout = 1 * time.Second
 	pinger.OnRecv = func(pkt *probing.Packet) {

+ 9 - 0
ping/probing/cfglog.go

@@ -0,0 +1,9 @@
+package probing
+
+import (
+	cfg "git.wecise.com/wecise/common/matrix/cfg"
+	log "git.wecise.com/wecise/common/matrix/logger"
+)
+
+var mcfg = cfg.MConfig()
+var logger = log.New().WithConfig(mcfg, "log|default")

+ 7 - 7
ping/probing/icmp/packetconn.go

@@ -175,10 +175,6 @@ func (mp *MPacketConn) SendPacket(pkt *Packet) error {
 	if mp.conn == nil {
 		return ENOLISTENER
 	}
-	msgBytes, err := pkt.BuildEchoRequestMessage(mp.conn.ICMPRequestType())
-	if err != nil {
-		return err
-	}
 	var dst net.Addr = pkt.IPAddr
 	if mp.Protocol == "udp" {
 		dst = &net.UDPAddr{IP: pkt.IPAddr.IP, Zone: pkt.IPAddr.Zone}
@@ -189,6 +185,10 @@ func (mp *MPacketConn) SendPacket(pkt *Packet) error {
 			return nil
 		default:
 		}
+		msgBytes, err := pkt.BuildEchoRequestMessage(mp.conn.ICMPRequestType())
+		if err != nil {
+			return err
+		}
 		if _, err := mp.conn.WriteTo(msgBytes, dst); err != nil {
 			if neterr, ok := err.(*net.OpError); ok {
 				if neterr.Err == syscall.ENOBUFS {
@@ -271,9 +271,9 @@ func (mp *MPacketConn) processEchoReply(pkt *icmp.Echo, recv *recvPkt) error {
 	fullid := int(binary.BigEndian.Uint64(pkt.Data[16:24]))
 	pktuuid := uuid.Must(uuid.FromBytes(pkt.Data[24:40]))
 
-	if fullid%65536 != pkt.ID || fullseq%65536 != pkt.Seq {
-		return nil
-	}
+	// if fullid%65536 != pkt.ID || fullseq%65536 != pkt.Seq {
+	// 	return nil
+	// }
 
 	// fmt.Printf("%s %d bytes from %s: icmp_seq=%d time=%v\n",
 	// 	time.Now().Format("15:04:05.000"), recv.nbytes, recv.addr, fullseq, recv.recvtime.Sub(time.Unix(0, sendtime)))

+ 0 - 1
ping/probing/mpconn.go

@@ -8,7 +8,6 @@ import (
 	"time"
 	"trial/ping/probing/icmp"
 
-	"git.wecise.com/wecise/common/logger"
 	"github.com/google/uuid"
 )
 

+ 38 - 73
ping/probing/ping.go

@@ -62,13 +62,10 @@ import (
 	"time"
 	"trial/ping/probing/icmp"
 
-	"git.wecise.com/wecise/common/logger"
-	"git.wecise.com/wecise/common/matrix/cfg"
 	"github.com/google/uuid"
 	"golang.org/x/sync/errgroup"
 )
 
-var mcfg = cfg.MConfig()
 var receive_buffer_count = mcfg.GetInt("ping.recv.buf.count", 10)
 var ping_ttl = mcfg.GetInt("ping.ttl", 64)
 var ping_interval = mcfg.GetDuration("ping.interval", 1000*time.Millisecond)
@@ -87,9 +84,6 @@ const (
 // New returns a new Pinger struct pointer.
 func New(addr string) *Pinger {
 	r := rand.New(rand.NewSource(getSeed()))
-	firstUUID := uuid.New()
-	var firstSequence = map[uuid.UUID]map[int]struct{}{}
-	firstSequence[firstUUID] = make(map[int]struct{})
 	return &Pinger{
 		Count:      -1,
 		Interval:   time.Second,
@@ -97,15 +91,13 @@ func New(addr string) *Pinger {
 		Size:       timeSliceLength + trackerLength,
 		Timeout:    time.Duration(math.MaxInt64),
 
-		addr:              addr,
-		done:              make(chan interface{}),
-		id:                r.Intn(math.MaxUint16),
-		trackerUUIDs:      []uuid.UUID{firstUUID},
-		ipaddr:            nil,
-		ipv4:              false,
-		network:           "ip",
-		protocol:          "udp",
-		awaitingSequences: firstSequence,
+		addr:     addr,
+		done:     make(chan interface{}),
+		id:       r.Intn(math.MaxUint16),
+		ipaddr:   nil,
+		ipv4:     false,
+		network:  "ip",
+		protocol: "udp",
 	}
 }
 
@@ -117,6 +109,9 @@ func NewPinger(addr string) (*Pinger, error) {
 
 // Pinger represents a packet sender/receiver.
 type Pinger struct {
+	// Size of packet being sent
+	Size int
+
 	// Interval is the wait time between each packet send. Default is 1s.
 	Interval time.Duration
 
@@ -129,9 +124,6 @@ type Pinger struct {
 	// interrupted.
 	Count int
 
-	// Debug runs in debug mode
-	Debug bool
-
 	// Number of packets sent
 	PacketsSent int
 
@@ -174,12 +166,6 @@ type Pinger struct {
 	// OnDuplicateRecv is called when a packet is received that has already been received.
 	OnDuplicateRecv func(*Packet)
 
-	// Size of packet being sent
-	Size int
-
-	// Tracker: Used to uniquely identify packets - Deprecated
-	Tracker uint64
-
 	// Source is the source IP address
 	Source string
 
@@ -190,15 +176,9 @@ type Pinger struct {
 	ipaddr *net.IPAddr
 	addr   string
 
-	// trackerUUIDs is the list of UUIDs being used for sending packets.
-	trackerUUIDs []uuid.UUID
-
 	ipv4          bool
 	id            int
 	sequence_base int
-	sequence      int
-	// awaitingSequences are in-flight sequence numbers we keep track of to help remove duplicate receipts
-	awaitingSequences map[uuid.UUID]map[int]struct{}
 	// network is one of "ip", "ip4", or "ip6".
 	network string
 	// protocol is "icmp" or "udp".
@@ -207,26 +187,20 @@ type Pinger struct {
 
 // Packet represents a received and processed ICMP echo packet.
 type Packet struct {
-	// Rtt is the round-trip time it took to ping.
-	Rtt time.Duration
-
-	// IPAddr is the address of the host being pinged.
-	IPAddr *net.IPAddr
-
 	// Host is the string address of the host being pinged.
 	Host string
-
-	// NBytes is the number of bytes in the message.
-	Nbytes int
-
+	// IPAddr is the address of the host being pinged.
+	IPAddr *net.IPAddr
+	// ID is the ICMP identifier.
+	ID int
 	// Seq is the ICMP sequence number.
 	Seq int
-
+	// NBytes is the number of bytes in the message.
+	Nbytes int
 	// TTL is the Time To Live on the packet.
 	TTL int
-
-	// ID is the ICMP identifier.
-	ID int
+	// Rtt is the round-trip time it took to ping.
+	Rtt time.Duration
 }
 
 // Statistics represent the stats of a currently running or finished
@@ -358,6 +332,14 @@ func (p *Pinger) SetNetwork(n string) {
 	}
 }
 
+/*
+	https://stackoverflow.com/questions/41423637/go-ping-library-for-unprivileged-icmp-ping-in-golang/41425527#41425527
+	This library attempts to send an "unprivileged" ping via UDP. On linux, this must be enabled by setting
+	sudo sysctl -w net.ipv4.ping_group_range="0   2147483647"
+	If you do not wish to do this, you can set pinger.SetPrivileged(true) and use setcap to allow your binary using go-ping to bind to raw sockets (or just run as super-user):
+	setcap cap_net_raw=+ep /bin/goping-binary
+	getcap /bin/goping-binary to validate
+*/
 // SetPrivileged sets the type of ping pinger will send.
 // false means pinger will send an "unprivileged" UDP ping.
 // true means pinger will send a "privileged" raw ICMP ping.
@@ -491,25 +473,25 @@ func (p *Pinger) runLoop() (time.Time, error) {
 		p.PacketsSent++
 		if p.OnSend != nil {
 			p.OnSend(&Packet{
-				Rtt:    pkt.Rtt,
-				IPAddr: pkt.IPAddr,
 				Host:   p.addr,
-				Nbytes: pkt.Nbytes,
+				IPAddr: pkt.IPAddr,
+				ID:     pkt.ID,
 				Seq:    pkt.Seq - p.sequence_base,
+				Nbytes: pkt.Nbytes,
 				TTL:    pkt.TTL,
-				ID:     pkt.ID,
+				Rtt:    pkt.Rtt,
 			})
 		}
 	}
 	pinfo.OnRecv = func(pkt *icmp.Packet) {
 		inpkt := &Packet{
-			Rtt:    pkt.Rtt,
-			IPAddr: pkt.IPAddr,
 			Host:   p.addr,
-			Nbytes: pkt.Nbytes,
+			IPAddr: pkt.IPAddr,
+			ID:     pkt.ID,
 			Seq:    pkt.Seq - p.sequence_base,
+			Nbytes: pkt.Nbytes,
 			TTL:    pkt.TTL,
-			ID:     pkt.ID,
+			Rtt:    pkt.Rtt,
 		}
 		if p.OnRecv != nil {
 			p.OnRecv(inpkt)
@@ -519,13 +501,13 @@ func (p *Pinger) runLoop() (time.Time, error) {
 	}
 	pinfo.OnRecvDup = func(pkt *icmp.Packet) {
 		inpkt := &Packet{
-			Rtt:    pkt.Rtt,
-			IPAddr: pkt.IPAddr,
 			Host:   p.addr,
-			Nbytes: pkt.Nbytes,
+			IPAddr: pkt.IPAddr,
+			ID:     pkt.ID,
 			Seq:    pkt.Seq - p.sequence_base,
+			Nbytes: pkt.Nbytes,
 			TTL:    pkt.TTL,
-			ID:     pkt.ID,
+			Rtt:    pkt.Rtt,
 		}
 		if p.OnDuplicateRecv != nil {
 			p.OnDuplicateRecv(inpkt)
@@ -628,27 +610,10 @@ func (p *Pinger) Statistics() *Statistics {
 	return &s
 }
 
-func bytesToTime(b []byte) time.Time {
-	var nsec int64
-	for i := uint8(0); i < 8; i++ {
-		nsec += int64(b[i]) << ((7 - i) * 8)
-	}
-	return time.Unix(nsec/1000000000, nsec%1000000000)
-}
-
 func isIPv4(ip net.IP) bool {
 	return len(ip.To4()) == net.IPv4len
 }
 
-func timeToBytes(t time.Time) []byte {
-	nsec := t.UnixNano()
-	b := make([]byte, 8)
-	for i := uint8(0); i < 8; i++ {
-		b[i] = byte((nsec >> ((7 - i) * 8)) & 0xff)
-	}
-	return b
-}
-
 var seed = time.Now().UnixNano()
 
 // getSeed returns a goroutine-safe unique seed

+ 7 - 0
ping/probing/readme.txt

@@ -0,0 +1,7 @@
+
+su - root
+sudo sysctl -w net.ipv4.ping_group_range="0   4294967295"
+setcap cap_net_raw=+ep mping
+chmod u+s mping
+
+