Last active
October 25, 2023 23:18
-
-
Save pahud/44b20faf97aba71206a0199deec6386c to your computer and use it in GitHub Desktop.
WAF update ip set
This file contains 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
#!/usr/bin/env python | |
import boto3 | |
client = boto3.client('waf-regional', region_name='us-east-1') | |
ipSetId='<YOUR_IP_SET_ID>' | |
def getChangeToken(): | |
response = client.get_change_token() | |
return response['ChangeToken'] | |
# print(getChangeToken()) | |
while True: | |
response = client.get_ip_set(IPSetId=ipSetId) | |
update_sets = [] | |
for i in response['IPSet']['IPSetDescriptors'][:1000]: | |
t = { | |
'Action': 'DELETE', | |
'IPSetDescriptor': i | |
} | |
update_sets.append(t) | |
#print(update_sets) | |
print('deleting %s item(s)' % len(update_sets)) | |
if len(update_sets) > 0: | |
response = client.update_ip_set( | |
IPSetId=ipSetId, | |
ChangeToken=getChangeToken(), | |
Updates=update_sets | |
) | |
print(response) | |
else: | |
print('all deleted') | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment