Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Last active August 20, 2023 21:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save carlessanagustin/526298ea7e9cc8554cf4c6ce3d9eedb2 to your computer and use it in GitHub Desktop.
Save carlessanagustin/526298ea7e9cc8554cf4c6ce3d9eedb2 to your computer and use it in GitHub Desktop.
Generate a list of StatusCake IP addresses to allow in firewall
<?php
/**
* Generate a list of Status Cake Ip addresses
* To add allowed IPs to Nginx or Firewall
* from: https://www.statuscake.com/kb/knowledge-base/what-are-your-ips/
*/
$statuscake_locations_json = "https://app.statuscake.com/Workfloor/Locations.php?format=json";
$locations = json_decode(file_get_contents($statuscake_locations_json));
$output = "#STATUS CAKE IPs" . "\n";
/**
* Formatted for Nginx
*/
foreach($locations as $location) {
$output .= "allow " . $location->ip . ";" . "\n";
}
print_r($output);
#!/usr/bin/env python3
import requests
import json
import subprocess
debug=False
url = 'https://app.statuscake.com/Workfloor/Locations.php?format=json'
comment = 'statuscake.com'
command = 'sudo iptables '
def add_rules( url, comment, command ):
print ('** Adding...')
global json
content = requests.get(url)
json = json.loads(content.content)
for item in json:
rule = command + '-I INPUT -s ' + json[item]['ip'] + '/32 -p tcp -m tcp --dport 80 -m comment --comment "' + comment + '" -j ACCEPT'
if debug: print (rule)
if not debug: subprocess.run(rule, shell=True)
def delete_rules( comment, command ):
print ('** Deleting...')
rules = command + '-S | grep "' + comment + '"'
try:
output = subprocess.check_output(rules,shell=True,stderr=subprocess.STDOUT)
for line_b in output.splitlines():
line_l = list (line_b.decode("utf-8"))
line_l[1] = 'D'
rule = command + ''.join(line_l)
if debug: print (rule)
if not debug: subprocess.run(rule, shell=True)
except subprocess.CalledProcessError:
pass
delete_rules( comment, command )
add_rules( url, comment, command )
@floptical
Copy link

Nifty scripts, thanks for having this up

@roeniss
Copy link

roeniss commented Mar 14, 2022

I think below link is up to date:
https://www.statuscake.com/locations/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment