-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
use_cloudflare_dns.sh
36 lines (31 loc) · 932 Bytes
/
use_cloudflare_dns.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Description: Sets all network interfaces but only
# for the network interfaces that are not compliant.
function not_cloudflare_dns {
INTERFACE=$1
if [ "$INTERFACE" = "An asterisk (*) denotes that a network service is disabled." ]; then
echo 0
else
DNS=$(networksetup -getdnsservers "$INTERFACE" | tr -d "\n")
if [ "$DNS" != "1.1.1.11.0.0.1" ]; then
echo 1
else
echo 0
fi
fi
}
export -f not_cloudflare_dns
function set_cloudflare_dns {
INTERFACE=$1
sudo networksetup -setdnsservers "$INTERFACE" 1.1.1.1 1.0.0.1
}
export -f set_cloudflare_dns
function process {
INTERFACE=$1
IS_NOT_CLOUDFLARE_DNS=$(not_cloudflare_dns "$INTERFACE")
if [ "$IS_NOT_CLOUDFLARE_DNS" = "1" ]; then
set_cloudflare_dns "$INTERFACE"
fi
}
export -f process
networksetup listallnetworkservices | xargs -I{} bash -c 'process "{}"'