I'm trying to create a script that:
Step 1 - Extract the resolver name in the file "S09dnscrypt-proxy".
Step 2 - Lookup the resolver name and get its ip address.
Step 3 - Add this ip address to the dnscrypt_ips ipset set.
Step 4 - Iterate for additional S09dnscrypt-proxy* files, if any.
I came up with the following partial solution.
a) Extracts DNSCrypt resolver names from all filenames beginning with "S09dnscrypt-proxy" in the /mnt/sda1/entware-ng.arm/etc/init.d directory.
b) Performs a lookup for the resolver names' ip address
c) Adds the resolver names' ip addresses to an ipset set called dnscrypt_ips
Currently, there are two S09dnscrypt-proxy files. In the future, there could be more by appending the next number to the end of the base filename "S09dnscrypt-proxy".
S09dnscrypt-proxy
S09dnscrypt-proxy1
b) Performs a lookup for the resolver names' ip address
c) Adds the resolver names' ip addresses to an ipset set called dnscrypt_ips
Currently, there are two S09dnscrypt-proxy files. In the future, there could be more by appending the next number to the end of the base filename "S09dnscrypt-proxy".
S09dnscrypt-proxy
S09dnscrypt-proxy1
Step 1 - Extract the resolver name in the file "S09dnscrypt-proxy".
Each of the S09dnscrypt-proxy* files contain the following line where the resolver name to be extracted is after the "-R ".
ARGS="--local-address=127.0.0.1:40 --daemonize -R dnscrypt.eu-dk"
In this example, the resolver name is "dnscrypt.eu-dk".
ARGS="--local-address=127.0.0.1:40 --daemonize -R dnscrypt.eu-dk"
In this example, the resolver name is "dnscrypt.eu-dk".
Step 2 - Lookup the resolver name and get its ip address.
Resolver names are stored in /opt/share/dnscrypt-proxy/dnscrypt-resolvers.csv. There are dozens of lines in this file, each starting with a different resolver name. Below is an example file.
https://github.com/jedisct1/dnscrypt-proxy/blob/master/dnscrypt-resolvers.csv
The column headers in this file are as follows:
Name,"Full name","Description","Location","Coordinates",URL,Version,DNSSEC validation,No logs,Namecoin,Resolver address,Provider name,Provider public key,Provider public key TXT record
In this file, the dnscrypt.eu-dk line is as follows:
https://github.com/jedisct1/dnscrypt-proxy/blob/master/dnscrypt-resolvers.csv
The column headers in this file are as follows:
Name,"Full name","Description","Location","Coordinates",URL,Version,DNSSEC validation,No logs,Namecoin,Resolver address,Provider name,Provider public key,Provider public key TXT record
In this file, the dnscrypt.eu-dk line is as follows:
dnscrypt.eu-dk,"DNSCrypt.eu Denmark","Free, non-logged, uncensored. Hosted by Netgroup.","Denmark","","https://dnscrypt.eu,1,yes,yes,no,77.66.84.233,2.dnscrypt-cert.resolver2.dnscrypt.eu,3748:5585:E3B9088:FD25:AD36:B037:01F5:520C648:9E9AD52:1457:4955:9F0A:9955,pubkey.resolver2.dnscrypt.eu"
The ip address to be extracted is "77.66.84.233".
Step 3 - Add this ip address to the dnscrypt_ips ipset set.
Code:
ipset create DNSCRYPT_IPS hash:ip
ipset add dnscrypt_ips 77.66.84.233
Step 4 - Iterate for additional S09dnscrypt-proxy* files, if any.
I came up with the following partial solution.
1) Create a script with the following commands.
... which returns
dnscrypt.eu-dk,
NOTE: This only works if the syntax of the "ARGS=" line doesn't change. I'd prefer to determine the position of the character after the string "-R " (note the space character) and extract the following consecutive characters up to the next quote OR space character.
Lookup the resolver's name in the .CSV file and extract the characters between the 10th and 11th commas.
Iterate for additional files.
Code:
#!/bin/sh
#DNSCRYPT_RES1 variable = Search for the line that begins with "ARGS=" (without quotes) and print the 4th column.
export DNSCRYPT_RES1=$(awk ' /^ARGS=/ {print $4}' /mnt/sda1/entware-ng.arm/etc/init.d/S09dnscrypt-proxy | sed 's/"/,/')
... which returns
dnscrypt.eu-dk,
NOTE: This only works if the syntax of the "ARGS=" line doesn't change. I'd prefer to determine the position of the character after the string "-R " (note the space character) and extract the following consecutive characters up to the next quote OR space character.
Iterate for additional files.
Last edited: