Last active
October 16, 2024 15:25
-
-
Save LeiHao0/4a4235df0fb97d559f9876eab0ebb5a4 to your computer and use it in GitHub Desktop.
Batch add block list in Adguard Home
This file contains hidden or 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
// https://github.com/AdguardTeam/AdGuardHome/blob/master/openapi/openapi.yaml | |
old_blist = []; | |
blist = [ | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts", | |
"https://v.firebog.net/hosts/static/w3kbl.txt", | |
"https://raw.githubusercontent.com/matomo-org/referrer-spam-blacklist/master/spammers.txt", | |
"https://someonewhocares.org/hosts/zero/hosts", | |
"https://raw.githubusercontent.com/VeleSila/yhosts/master/hosts", | |
"https://winhelp2002.mvps.org/hosts.txt", | |
"https://v.firebog.net/hosts/neohostsbasic.txt", | |
"https://raw.githubusercontent.com/RooneyMcNibNug/pihole-stuff/master/SNAFU.txt", | |
"https://paulgb.github.io/BarbBlock/blacklists/hosts-file.txt", | |
"https://adaway.org/hosts.txt", | |
"https://v.firebog.net/hosts/AdguardDNS.txt", | |
"https://v.firebog.net/hosts/Admiral.txt", | |
"https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt", | |
"https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt", | |
"https://v.firebog.net/hosts/Easylist.txt", | |
"https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts", | |
"https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts", | |
"https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts", | |
"https://v.firebog.net/hosts/Easyprivacy.txt", | |
"https://v.firebog.net/hosts/Prigent-Ads.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts", | |
"https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt", | |
"https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt", | |
"https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/android-tracking.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/AmazonFireTV.txt", | |
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt", | |
"https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt", | |
"https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt", | |
"https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt", | |
"https://v.firebog.net/hosts/Prigent-Crypto.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts", | |
"https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt", | |
"https://phishing.army/download/phishing_army_blocklist_extended.txt", | |
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt", | |
"https://v.firebog.net/hosts/RPiList-Malware.txt", | |
"https://v.firebog.net/hosts/RPiList-Phishing.txt", | |
"https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt", | |
"https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts", | |
"https://urlhaus.abuse.ch/downloads/hostfile/", | |
"https://malware-filter.gitlab.io/malware-filter/phishing-filter-hosts.txt", | |
"https://v.firebog.net/hosts/Prigent-Malware.txt", | |
"https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser", | |
]; | |
alist = [ | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt", | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt", | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt", | |
]; | |
url = "http://127.0.0.1/control/filtering/"; | |
function updateList(list, mode) { | |
path = mode == "rm" ? "remove_url" : "add_url"; | |
whitelist = mode == "whitelist" ? true : false; | |
for (i in list) { | |
l = list[i]; | |
fetch(url + path, { | |
method: "POST", | |
body: | |
mode == "rm" | |
? JSON.stringify({ | |
url: l, | |
whitelist: whitelist, | |
}) | |
: JSON.stringify({ | |
name: l.substr(-10), | |
url: l, | |
whitelist: whitelist, | |
}), | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
}) | |
.then((response) => response.text()) | |
.then((data) => console.log(data)); | |
} | |
} | |
updateList(old_blist, "rm"); | |
updateList(blist, "add"); | |
updateList(alist, "whitelist"); |
This file contains hidden or 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
from requests.adapters import HTTPAdapter | |
from requests.packages.urllib3.poolmanager import PoolManager | |
import ssl | |
import requests | |
import json | |
## CHANGE HERE ## | |
# ip address of AdGuard Home | |
# "http(s)://<adguardHomeIp:<port>" | |
host = "http://192.168.2.2:80" | |
proxies = { | |
"http": "http://127.0.0.1:7890", | |
"https": "http://127.0.0.1:7890", | |
} | |
# user name | |
userName = "" | |
# password | |
password = "" | |
# block list | |
# taken from Wally3K's Firebog https://firebog.net/ | |
urls = [ | |
"https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts", | |
"https://v.firebog.net/hosts/static/w3kbl.txt", | |
"https://raw.githubusercontent.com/matomo-org/referrer-spam-blacklist/master/spammers.txt", | |
"https://someonewhocares.org/hosts/zero/hosts", | |
"https://raw.githubusercontent.com/VeleSila/yhosts/master/hosts", | |
"https://winhelp2002.mvps.org/hosts.txt", | |
"https://v.firebog.net/hosts/neohostsbasic.txt", | |
"https://raw.githubusercontent.com/RooneyMcNibNug/pihole-stuff/master/SNAFU.txt", | |
"https://paulgb.github.io/BarbBlock/blacklists/hosts-file.txt", | |
"https://adaway.org/hosts.txt", | |
"https://v.firebog.net/hosts/AdguardDNS.txt", | |
"https://v.firebog.net/hosts/Admiral.txt", | |
"https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt", | |
"https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt", | |
"https://v.firebog.net/hosts/Easylist.txt", | |
"https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts", | |
"https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts", | |
"https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts", | |
"https://v.firebog.net/hosts/Easyprivacy.txt", | |
"https://v.firebog.net/hosts/Prigent-Ads.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts", | |
"https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt", | |
"https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt", | |
"https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/android-tracking.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/AmazonFireTV.txt", | |
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt", | |
"https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt", | |
"https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt", | |
"https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt", | |
"https://v.firebog.net/hosts/Prigent-Crypto.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts", | |
"https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt", | |
"https://phishing.army/download/phishing_army_blocklist_extended.txt", | |
"https://malware-filter.gitlab.io/malware-filter/phishing-filter-hosts.txt", | |
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt", | |
"https://v.firebog.net/hosts/RPiList-Malware.txt", | |
"https://v.firebog.net/hosts/RPiList-Phishing.txt", | |
"https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt", | |
"https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts", | |
"https://urlhaus.abuse.ch/downloads/hostfile/", | |
"https://v.firebog.net/hosts/Prigent-Malware.txt", | |
"https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser", | |
] | |
allow_urls = [ | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt", | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt", | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt", | |
] | |
############ End Edits ################# | |
# Open TLSv1 Adapter | |
class MyAdapter(HTTPAdapter): | |
def init_poolmanager(self, connections, maxsize, block=False): | |
self.poolmanager = PoolManager(num_pools=connections, | |
maxsize=maxsize, | |
block=block, | |
ssl_version=ssl.PROTOCOL_TLSv1) | |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0', 'Content-Type':'application/json'} | |
s = requests.Session() | |
s.mount(host, MyAdapter()) | |
x = s.post(host + "/control/login", json.dumps({"name": userName, "password" : password}), headers=headers, proxies=proxies) | |
print(x.text) | |
for u in urls: | |
filterObj = json.dumps({'url':u, "name":u,"whitelist":False}) | |
print(filterObj) | |
x = s.post(host + "/control/filtering/add_url", data = filterObj, headers=headers) | |
print(x.text) | |
for u in allow_urls: | |
filterObj = json.dumps({'url':u, "name":u,"whitelist":True}) | |
print(filterObj) | |
x = s.post(host + "/control/filtering/add_url", data = filterObj, headers=headers) | |
print(x.text) | |
# help from | |
# https://stackoverflow.com/questions/30946370/using-requests-to-login-to-a-website-that-has-javascript-login-form | |
# https://stackoverflow.com/questions/33818206/python-login-into-a-website-with-javascript-form |
Hello @LeiHao0, i tried from the chrome console as you suggested the items are added but i get the following error:
Uncaught (in promise) SyntaxError: Unexpected token 'F', "Filter URL"... is not valid JSON
should the js version be modiified for this latest adguard version?
@vannimb fixed.
the SyntaxError caused by AdGuardHome API response is a string
instead of a json
. This means the list still can be added in for the previous version.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @vannimb, thank you for your commands. You can try the javascript version. It's more straightforward and can be executed with the chrome console.