예제 #1
0
def _add_pretty_mac_column(df: pd.DataFrame, col_name: Text) -> pd.DataFrame:
    """Adds a column with pretty representation of MAC address value.

  Args:
    df: Dataframe to add a column to.
    col_name: Name of MAC address column.

  Returns:
    Dataframe with a column added.
  """

    if col_name not in df.columns:
        return df

    def convert_to_pretty_str(packed: bytes) -> Text:
        if pd.isna(packed):
            return np.nan
        return client_textify.mac(packed)

    pretty_values = [convert_to_pretty_str(packed) for packed in df[col_name]]
    return convert.add_pretty_column(df, col_name, pretty_values)
예제 #2
0
def _add_pretty_ipaddress_column(df, col_name):
    """Adds a column with pretty representation of IP address value.

  Args:
    df: Dataframe to add a column to.
    col_name: Name of IP address column.

  Returns:
    Dataframe with a column added.
  """

    if col_name not in df.columns:
        return df

    def convert_to_pretty_str(packed):
        if len(packed) == 4:
            return str(ipaddress.IPv4Address(packed))
        return str(ipaddress.IPv6Address(packed))

    pretty_values = [convert_to_pretty_str(packed) for packed in df[col_name]]
    return convert.add_pretty_column(df, col_name, pretty_values)
예제 #3
0
def _add_pretty_mac_column(df, col_name):
    """Adds a column with pretty representation of MAC address value.

  Args:
    df: Dataframe to add a column to.
    col_name: Name of MAC address column.

  Returns:
    Dataframe with a column added.
  """

    if col_name not in df.columns:
        return df

    def convert_to_pretty_str(packed):
        if pd.isna(packed):
            return np.nan
        # TODO: In Python3 new_bytes call is noop but in Python2 it
        #  will convert old bytes to future compatible interface. Remove as soon as
        #  support for Python2 is dropped.
        return ':'.join('{:02x}'.format(b) for b in new_bytes(packed))

    pretty_values = [convert_to_pretty_str(packed) for packed in df[col_name]]
    return convert.add_pretty_column(df, col_name, pretty_values)