{"id":20249542,"url":"https://github.com/crzidea/doh","last_synced_at":"2025-04-06T11:07:39.826Z","repository":{"id":254422423,"uuid":"846482522","full_name":"crzidea/doh","owner":"crzidea","description":"Country-Aware DNS over HTTPS for Optimized CDN Routing","archived":false,"fork":false,"pushed_at":"2025-03-25T10:40:12.000Z","size":34,"stargazers_count":93,"open_issues_count":0,"forks_count":27,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T10:08:58.821Z","etag":null,"topics":["dns","dns-over-https","doh"],"latest_commit_sha":null,"homepage":"https://crzidea.com/#/article/introducing-crzidea-doh","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crzidea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-23T09:56:45.000Z","updated_at":"2025-03-14T09:56:08.000Z","dependencies_parsed_at":"2024-08-27T10:59:36.918Z","dependency_job_id":"c1c8e8b0-9bd8-4a90-a0d4-bc20844f10b6","html_url":"https://github.com/crzidea/doh","commit_stats":{"total_commits":48,"total_committers":1,"mean_commits":48.0,"dds":0.0,"last_synced_commit":"ac6ebfe7e14fc59c024aa2c41ebbbce222586892"},"previous_names":["crzidea/doh"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crzidea%2Fdoh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crzidea%2Fdoh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crzidea%2Fdoh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crzidea%2Fdoh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crzidea","download_url":"https://codeload.github.com/crzidea/doh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471517,"owners_count":20944158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","dns-over-https","doh"],"created_at":"2024-11-14T09:54:17.205Z","updated_at":"2025-04-06T11:07:39.807Z","avatar_url":"https://github.com/crzidea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Country-Aware DNS over HTTPS for Optimized CDN Routing\n\nThis Cloudflare Worker script provides a DNS over HTTPS (DoH) service with intelligent ECS (EDNS Client Subnet) handling for improved CDN performance.\n\n[中文介绍](https://crzidea.com/#/article/introducing-crzidea-doh)\n\n![](https://www.plantuml.com/plantuml/png/bP7HRjCm58RlznI7NWs9sXfi876rAKLT9T95BTc4fgboujFMmh63VRokF3sEILKQxMQNFZxVdo-_hpq9Hw7HP--KgNMG25kYrd_bt8aTsoZQXYfuTBKrX8PORHlUQc4wPkn9QbNnx79STACo_yuRuGbT7AsoZdWXrdRff4WZrEwFaYYujDkpvJukDkVJcmymcYgw3HNSrAIiyQCu6Rq_BEHvFERY9LT6djva3_6OQHlaMWk7y63TBtG3F9kSBaqk-liYhbfpNiPJwT5rquczXKmhD7Jafnq_jNQZ8pjVzl02TJ9FSXSCYg0rJD7E2f22H2KymjhP1WxYHoG9VMHGjjeAEOJ8mgdi4Ko_-ud112Ev_x_BdXhqqADbJruoME3lW9uEBzoXp8TAsaOemtR_C2RncTUfXR5g-UDiMQncnTDXLDjWoEtvOtPNpdyiVgwokyct9ouqeJE2r3CcwhwO9qeQFuuVTVlUfbD9bLwzecCyswIcZnZi56qXEa1iAReQf67IvxSaHQzNazAhV65mBxIIWX0S-g09x1fS7twL4WOF5YEkqSZGwBy0)\n\n## How it works:\n\n1. **ECS Extraction:** The worker extracts two sets of ECS options from URL:\n\n   - **Client IP:** The actual IP address of the client making the request.\n   - **Alternative IP:** Typically, the external IP address of a VPN connection.\n\n2. **Dual DNS Resolution:** The worker performs two DNS resolutions for each request, one using the client IP and one using the alternative IP.\n\n3. **Intelligent Response Selection:** The worker compares the IP addresses returned in both DNS responses:\n   - **Same Country Match:** If the IP address returned using the client IP is located in the same country as the client, that response is chosen. This prioritizes local CDN nodes for optimal performance.\n   - **Alternative IP Response:** If the client IP response doesn't match the client's country, the response obtained using the alternative IP is chosen. This ensures content delivery even when using a VPN or experiencing routing issues.\n\n## Benefits:\n\n- **Improved CDN Performance:** By intelligently selecting the best DNS response based on client location, the worker ensures requests are routed to the most optimal CDN nodes.\n- **Enhanced Privacy:** Utilizing DoH encrypts DNS queries, preventing eavesdropping and manipulation.\n- **Seamless VPN Integration:** The worker's dual resolution approach ensures uninterrupted content delivery even when using a VPN.\n\n## Deployment:\n\nThis worker is designed for deployment on the Cloudflare Workers platform. Here are the steps to deploy:\n\n1. **Install dependencies:**\n\n   ```bash\n   npm install\n   ```\n\n2. **（Optional）Login to Wrangler:**\n\n   ```bash\n   npx wrangler login\n   ```\n\n3. **Download, create, and import the GeoIP database:**\n\n   You need to set following env vars before run the import script:\n\t```bash\n \texport MAXMIND_ACCOUNT_ID=\n\texport MAXMIND_LICENSE_KEY=\n\texport CLOUDFLARE_ACCOUNT_ID=\n\texport CLOUDFLARE_API_TOKEN=\n \t```\n   Note: The following permissions for cloudflare token are needed to run the script, you can visit [here](https://dash.cloudflare.com/profile/api-tokens) to create a new token:\n\t```\n \tAccount/Worker Scripts/Edit\n \tAccount/D1/Edit\n \t```\n   Then, run the script:\n \t```bash\n \t./import-geoip.sh\n \t```\n   The script will do the following tasks\n\t- Download the GeoLite2 Country database from MaxMind and extract it to the `./tmp` directory.\n   - Create a D1 database on Cloudflare and import the downloaded database into the D1 database.\n\n\n5. **Configure wrangler.toml:**\n\n\t```sh\n \tmv tmp/wrangler.toml .\n \t```\n\n6. **Deploy:**\n   ```bash\n   npm run deploy\n   ```\n\n## DoH URL Example:\n\nReplace `doh.subdomain.workers.dev` with your domain name after deploying the script to cloudflare workers.\n\n```\nhttps://doh.subdomain.workers.dev/client-ip/223.5.5.5/client-country/CN/alternative-ip/8.8.8.8/dns-query\n```\n\n## Contributing:\n\nContributions are welcome! Please feel free to open issues or submit pull requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrzidea%2Fdoh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrzidea%2Fdoh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrzidea%2Fdoh/lists"}