Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

dnsDomainIs here is not so accurate in MacOS #336

Open
54chen opened this issue Feb 13, 2021 · 1 comment
Open

dnsDomainIs here is not so accurate in MacOS #336

54chen opened this issue Feb 13, 2021 · 1 comment

Comments

@54chen
Copy link

54chen commented Feb 13, 2021

if (dnsDomainIs(host, domains[i])) {

If you have a domain in list like '138.com', 'ip138.com' will be matched in MacOS.

The better way is setting the list like '*.138.com', using shExpMatch instead of dnsDomainIs.

BTW: be careful, you must add 'twitter.com' in list, '*.twitter.com' will NOT hit it.

Here is an auto generating shell file enclosed.


#!/bin/bash
#
# 从 gfwlist 更新 pac.js

readonly GFWLIST_PATH="https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt"

# 扩展域名,添加额外需要代理的域名
declare -a EXTEND_DOMAINS
EXTEND_DOMAINS=( github.com githubusercontent.com )

echo -e "下载 gfwlist.txt..."

# 开头
cat << 'EOF' > pac.js
var V2Ray = "SOCKS5 127.0.0.1:1081; SOCKS 127.0.0.1:1081; DIRECT;";

var domains = [
EOF

# 域名
for line in "${EXTEND_DOMAINS[@]}"; do
  echo "  \"*.${line}\"," >> pac.js
  echo "  \"${line}\"," >> pac.js
done;

while IFS= read -r line; do
  if [[ "${line}" == .* ]]; then
    echo "  \"*.${line:1}\"," >> pac.js
    echo "  \"${line:1}\"," >> pac.js
  fi
  if [[ "${line}" == \|\|* ]]; then
    echo "  \"*.${line:2}\"," >> pac.js
    echo "  \"${line:2}\"," >> pac.js
  fi
#done < <(curl -sSfL "${GFWLIST_PATH}" | tr -d '\n' | base64 --decode)
done < <(curl -sSfL "${GFWLIST_PATH}" | tr -d '\n' | base64 --decode | sort | uniq)

# 结尾
cat << 'EOF' >> pac.js
];

function FindProxyForURL(url, host) {
    for (var i = domains.length - 1; i >= 0; i--) {
    	if (shExpMatch(host, domains[i])) {
            return V2Ray;
    	}
    }
    return "DIRECT";
}
EOF

echo -e "\n\033[32m更新完成 pac.js\033[0m\n"

Reference:
https://opensource.apple.com/source/CFNetwork/CFNetwork-128/PACSupport.js.auto.html

@didila
Copy link

didila commented Feb 25, 2021

其实pac已经可以功成身退了

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants