import ipaddress


def rule(event):
    if all(
        [
            event.deep_get("Initiated", default="") == "true",
            event.deep_get("DestinationPort", default="")
            in [888, 999, 2200, 2222, 4000, 4444, 6789, 8531, 50501, 51820],
            not any(
                [
                    ipaddress.ip_address(event.deep_get("DestinationIp", default=""))
                    in ipaddress.ip_network("127.0.0.0/8"),
                    ipaddress.ip_address(event.deep_get("DestinationIp", default=""))
                    in ipaddress.ip_network("10.0.0.0/8"),
                    ipaddress.ip_address(event.deep_get("DestinationIp", default=""))
                    in ipaddress.ip_network("172.16.0.0/12"),
                    ipaddress.ip_address(event.deep_get("DestinationIp", default=""))
                    in ipaddress.ip_network("192.168.0.0/16"),
                    ipaddress.ip_address(event.deep_get("DestinationIp", default=""))
                    in ipaddress.ip_network("169.254.0.0/16"),
                    ipaddress.ip_address(event.deep_get("DestinationIp", default=""))
                    in ipaddress.ip_network("::1/128"),
                    ipaddress.ip_address(event.deep_get("DestinationIp", default=""))
                    in ipaddress.ip_network("fe80::/10"),
                    ipaddress.ip_address(event.deep_get("DestinationIp", default=""))
                    in ipaddress.ip_network("fc00::/7"),
                ]
            ),
        ]
    ):
        return True
    return False
