Skip to content

Instantly share code, notes, and snippets.

@peterc
Created March 11, 2023 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterc/c7c2f0169efc8194940592d92571e91f to your computer and use it in GitHub Desktop.
Save peterc/c7c2f0169efc8194940592d92571e91f to your computer and use it in GitHub Desktop.
Get the IPs that MediaWiki / Wikipedia blocks programmatically
import requests
import time
# Initialize variables
api_url = "https://meta.wikimedia.org/w/api.php"
params = {
"action": "query",
"format": "json",
"list": "globalblocks",
"bglimit": "500"
}
blocked_ips = []
count = 0
while True:
response = requests.get(api_url, params=params)
response_json = response.json()
globalblocks = response_json["query"]["globalblocks"]
for block in globalblocks:
blocked_ips.append(block["address"])
print(block["address"])
if "continue" not in response_json:
break
count += 1
if count > 10:
break
params["bgstart"] = response_json["continue"]["bgstart"]
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment