{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# CNA MAP\n", "---" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-05-04T12:10:48.261138Z", "iopub.status.busy": "2024-05-04T12:10:48.260661Z", "iopub.status.idle": "2024-05-04T12:10:48.812460Z", "shell.execute_reply": "2024-05-04T12:10:48.811927Z" }, "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "from IPython.core.magic import register_cell_magic\n", "from IPython.display import Markdown\n", "import datetime\n", "from datetime import date\n", "import folium\n", "from folium.plugins import MarkerCluster\n", "from geopy.geocoders import Nominatim\n", "import json\n", "import pandas as pd\n", "import time" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-05-04T12:10:48.815142Z", "iopub.status.busy": "2024-05-04T12:10:48.814726Z", "iopub.status.idle": "2024-05-04T12:13:52.533288Z", "shell.execute_reply": "2024-05-04T12:13:52.532745Z" }, "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "\n", "\n", "with open('CNAsList.json') as f:\n", " data = json.load(f)\n", "\n", "CNA = pd.json_normalize(data)\n", "\n", "geolocator = Nominatim(user_agent=\"CNALookup\")\n", "latitude = []\n", "long = []\n", "for i in CNA[\"country\"]:\n", " if i != None:\n", " location = geolocator.geocode(i, timeout=None)\n", " if location!=None:\n", " latitude.append(location.latitude)#, location.longitude)\n", " long.append(location.longitude)\n", " else:\n", " latitude.append(float(\"Nan\"))#, location.longitude)\n", " long.append(float(\"Nan\"))\n", " else:\n", " latitude.append(float(\"Nan\"))#, location.longitude)\n", " long.append(float(\"Nan\"))\n", "\n", "CNA[\"Latitude\"] = latitude\n", "CNA[\"Longitude\"] = long" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-05-04T12:13:52.535851Z", "iopub.status.busy": "2024-05-04T12:13:52.535429Z", "iopub.status.idle": "2024-05-04T12:13:52.540835Z", "shell.execute_reply": "2024-05-04T12:13:52.540389Z" }, "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "pattern = r'(https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}[-a-zA-Z0-9()@:%_+.~#?&/=]*)' \n", "CNA['securityAdvisories.advisories'] = CNA['securityAdvisories.advisories'].astype(str)\n", "CNA['URL'] = CNA['securityAdvisories.advisories'].str.extract(pattern, expand=False).str.strip()\n", "CNA['URL'] = CNA['URL'].astype(str)\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-05-04T12:13:52.542888Z", "iopub.status.busy": "2024-05-04T12:13:52.542567Z", "iopub.status.idle": "2024-05-04T12:13:52.988346Z", "shell.execute_reply": "2024-05-04T12:13:52.987741Z" }, "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map = folium.Map(location=[10, 0], tiles='cartodb positron', zoom_start=2.25)\n", "\n", "mcluster = MarkerCluster().add_to(map)\n", "\n", "for index, row in CNA.iterrows():\n", " folium.Marker(location=[row['Latitude'],row['Longitude']], popup=(\"\"+row.organizationName+\"\" +\"\\n\"+\"
\"+row.URL),icon=folium.Icon(color='lightgray', icon='bug', prefix='fa')).add_to(mcluster)\n", "\n", "map\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This map is built from the data on [this page](https://www.cve.org/PartnerInformation/ListofPartners). More infomration about CNA's can be found [here](https://www.cve.org/ProgramOrganization/CNAs). " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-05-04T12:13:53.024493Z", "iopub.status.busy": "2024-05-04T12:13:53.024011Z", "iopub.status.idle": "2024-05-04T12:13:53.028143Z", "shell.execute_reply": "2024-05-04T12:13:53.027721Z" }, "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/markdown": [ "This report is updated automatically every day, last generated on: **2024-05-04 12:13:53.025418**" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Markdown(f\"This report is updated automatically every day, last generated on: **{datetime.datetime.now()}**\")" ] } ], "metadata": { "interpreter": { "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 4 }