IPTables and UFW problems

I think ChatGPT and the script from the first post could solve it.