def add_ip_cluster()

in msticpy/nbtools/foliummap.py [0:0]


    def add_ip_cluster(self, ip_entities: Iterable[IpAddress], **kwargs):
        """
        Add a collection of IP Entities to the map.

        Parameters
        ----------
        ip_entities : Iterable[IpAddress]
            a iterable of IpAddress Entities

        Other Parameters
        ----------------
            kwargs: icon properties to use for displaying this cluster

        """
        geo_entity = GeoLocation()
        geo_entity.CountryCode = "Unknown"
        geo_entity.CountryName = "Unknown"
        geo_entity.State = "Unknown"
        geo_entity.City = "Unknown"
        geo_entity.Longitude = 0.0  # type: ignore
        geo_entity.Latitude = 0.0  # type: ignore

        for ip_entity in ip_entities:
            if ip_entity.Location is None:
                ip_entity.Location = geo_entity

        for ip_entity in ip_entities:
            if ip_entity.Location is None:
                continue
            if (
                not (
                    isinstance(ip_entity.Location.Latitude, (int, float))
                    and isinstance(ip_entity.Location.Longitude, (int, float))
                )
                or math.isnan(ip_entity.Location.Latitude)
                or math.isnan(ip_entity.Location.Longitude)
            ):
                warnings.warn(
                    "Invalid location information for IP: " + ip_entity.Address,
                    RuntimeWarning,
                )
                continue
            loc_props = ", ".join(
                f"{key}={val}"
                for key, val in ip_entity.Location.properties.items()
                if val
            )

            popup_text = f"{loc_props}<br>IP: {ip_entity.Address}"
            if (
                "City" in ip_entity.Location.properties
                or "CountryName" in ip_entity.Location.properties
            ):
                tooltip_text = (
                    f"{ip_entity.Location.City}, {ip_entity.Location.CountryName}"
                )
            else:
                tooltip_text = (
                    f"{ip_entity.Location.Latitude}, {ip_entity.Location.Longitude}"
                )

            if ip_entity.AdditionalData:
                addl_props = ", ".join(
                    f"{key}={val}"
                    for key, val in ip_entity.AdditionalData.items()
                    if val
                )

                popup_text = f"{popup_text}<br>{addl_props}"
                tooltip_text = f"{tooltip_text}, {addl_props}"
            marker = folium.Marker(
                location=[ip_entity.Location.Latitude, ip_entity.Location.Longitude],
                popup=popup_text,
                tooltip=tooltip_text,
                icon=folium.Icon(**kwargs),
            )
            marker.add_to(self.folium_map)
            self.locations.append(
                (ip_entity.Location.Latitude, ip_entity.Location.Longitude)
            )