Last active
March 2, 2017 20:20
-
-
Save anatolinicolae/13b5605b5b94f0afcab93022b6ee2089 to your computer and use it in GitHub Desktop.
DNS Latency Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
209.244.0.3 | |
209.244.0.4 | |
64.6.64.6 | |
64.6.65.6 | |
8.8.8.8 | |
8.8.4.4 | |
84.200.69.80 | |
84.200.70.40 | |
8.26.56.26 | |
8.20.247.20 | |
208.67.222.222 | |
208.67.220.220 | |
156.154.70.1 | |
156.154.71.1 | |
199.85.126.10 | |
199.85.127.10 | |
81.218.119.11 | |
209.88.198.133 | |
195.46.39.39 | |
195.46.39.40 | |
96.90.175.167 | |
193.183.98.154 | |
208.76.50.50 | |
208.76.51.51 | |
216.146.35.35 | |
216.146.36.36 | |
37.235.1.174 | |
37.235.1.177 | |
198.101.242.72 | |
23.253.163.53 | |
77.88.8.8 | |
77.88.8.1 | |
91.239.100.100 | |
89.233.43.71 | |
74.82.42.42 | |
109.69.8.51 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for server in $(cat dns-list.txt); do | |
echo "$(sudo ping -f -c 100 $server | grep "rtt" | tr '/' '\n' | sed -n '5p') # IP: $server"; | |
done | sort --version-sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for server in $(cat dns-list.txt); do | |
if [[ `dig doesntexist.lol @$server +short | wc -l` -eq "0" ]]; then | |
echo $server; | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
"strconv" | |
"regexp" | |
"os/exec" | |
"sort" | |
) | |
type Server struct { | |
ip string | |
latency float64 | |
} | |
type ServerList []Server | |
func (s ServerList) Len() int { return len(s) } | |
func (s ServerList) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | |
func (s ServerList) Less(i, j int) bool { return s[i].latency < s[j].latency } | |
func get_ping(ip string) string { | |
r := regexp.MustCompile("icmp_seq=(\\d+) ttl=(\\d+) time=(\\d+.?\\d+) ms") | |
cmd := "ping -c 1 -w 1 " + ip | |
parts := strings.Fields(cmd) | |
head := parts[0] | |
parts = parts[1:len(parts)] | |
out, err := exec.Command(head, parts...).Output() | |
if err != nil { | |
return "-1" | |
} | |
res := r.FindStringSubmatch(string(out)) | |
return string(res[3]) | |
} | |
func main() { | |
const NO_LAT = -1 | |
servers := map[string]int { | |
"209.244.0.3": NO_LAT, | |
"209.244.0.4": NO_LAT, | |
"64.6.64.6": NO_LAT, | |
"64.6.65.6": NO_LAT, | |
"8.8.8.8": NO_LAT, | |
"8.8.4.4": NO_LAT, | |
"84.200.69.80": NO_LAT, | |
"84.200.70.40": NO_LAT, | |
"8.26.56.26": NO_LAT, | |
"8.20.247.20": NO_LAT, | |
"208.67.222.222": NO_LAT, | |
"208.67.220.220": NO_LAT, | |
"156.154.70.1": NO_LAT, | |
"156.154.71.1": NO_LAT, | |
"199.85.126.10": NO_LAT, | |
"199.85.127.10": NO_LAT, | |
"81.218.119.11": NO_LAT, | |
"209.88.198.133": NO_LAT, | |
"195.46.39.39": NO_LAT, | |
"195.46.39.40": NO_LAT, | |
"96.90.175.167": NO_LAT, | |
"193.183.98.154": NO_LAT, | |
"208.76.50.50": NO_LAT, | |
"208.76.51.51": NO_LAT, | |
"216.146.35.35": NO_LAT, | |
"216.146.36.36": NO_LAT, | |
"37.235.1.174": NO_LAT, | |
"37.235.1.177": NO_LAT, | |
"198.101.242.72": NO_LAT, | |
"23.253.163.53": NO_LAT, | |
"77.88.8.8": NO_LAT, | |
"77.88.8.1": NO_LAT, | |
"91.239.100.100": NO_LAT, | |
"89.233.43.71": NO_LAT, | |
"74.82.42.42": NO_LAT, | |
"109.69.8.51": NO_LAT, | |
} | |
s := make(ServerList, len(servers)) | |
fmt.Println("Analysing pings...") | |
i := 0 | |
for server := range servers { | |
time, err := strconv.ParseFloat(get_ping(server), 64) | |
if err == nil && time != NO_LAT { | |
s[i] = Server { server, time } | |
} else { | |
s[i] = Server { server, NO_LAT } | |
} | |
i++ | |
} | |
sort.Sort(s) | |
fmt.Println("\r\nResults:\r\n") | |
for _, k := range s { | |
if ( k.latency != NO_LAT ) { | |
fmt.Printf("%s \t%f\r\n", k.ip, k.latency) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment