Updates to sample notebook for blog

This commit is contained in:
Ian Hellen 2019-04-05 19:43:59 -07:00
Родитель 7fe5343e5c
Коммит 53f4d0bf3c
3 изменённых файлов: 987 добавлений и 158 удалений

Просмотреть файл

@ -0,0 +1,210 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a id='setup'></a>[Contents](#toc)\n",
"# Notebook Environment Setup\n",
"\n",
"Make sure that you have installed packages specified in the setup (uncomment the lines to execute)\n",
"\n",
"## Install Packages\n",
"The first time this cell runs for a new Azure Notebooks project or other Python environment it will take several minutes to download and install the packages. In subsequent runs it should run quickly and confirm that package dependencies are already installed. Unless you want to upgrade the packages you can feel free to skip execution of the next cell.\n",
"\n",
"If you see any import failures (```ImportError```) in the notebooks, please re-run this notebook and answer 'y' when prompted, then re-run the cell where the import failure occurred.\n",
"\n",
"Note you may see some warnings about incompatibility with certain packages. This should not affect the functionality of this notebook but you may need to upgrade the packages producing the warnings to a more recent version."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configuring your Python Environment\n",
"### Python 3.6 or Later\n",
"If you are running in Jupyterhub environment such as Azure Notebooks, Python is already installed. When using any of the sample notebooks or copies of them you only need to ensure that the Python 3.6 (or later) kernel is selected.\n",
"\n",
"If you are running the notebooks locally will you need to install Python 3.6 or later. The Ananconda distribution is a good starting point since it comes with many required packages already installed.\n",
"\n",
"### Creating a virtual environment\n",
"Before installing any of the packages it is a good idea to create a clean virtual python environment. This will prevent installed packages conflicting with versions that may be required for other applications.\n",
"\n",
"For standard python use the `virtualenv` command. For Conda use the `conda env` command. In both cases be sure to activate the environment before running jupyter using `active {my_env_name}`.\n",
"\n",
"\n",
"### Using Requirements.txt\n",
"In Notebooks for Azure you can configure \"Add a requirements.txt\" to the current project. See [this notebook](https://github.com/Azure/Azure-Sentinel/Notebooks/HowTos/AzureNotebooks-ConfigurePythonVersion.ipynb) for details.\n",
"\n",
"If running in another environment you can install most of the required packages by downloading `requirements.txt` from the [Azure Sentinel Github](https://github.com/Azure/Azure-Sentinel/Notebooks/requirements.txt).\n",
"\n",
"In a standard environment, you can simply run\n",
"\n",
"```\n",
"pip install -r requirements.txt\n",
"```\n",
"to install the requirements or run the following cell.\n",
"\n",
"### Installing in a Conda Environment\n",
"Although you can use pip inside a conda environment it is usually better to try to install conda packages whenever possible.\n",
"\n",
"```\n",
"activate {my_env_name}\n",
"conda config --append channels conda-forge\n",
"conda install package1 package2\n",
"```\n",
"\n",
"See [Managing packages](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html) in Anaconda.\n",
"\n",
"For packages that are not available as conda packages use pip from with a Conda prompt/shell to install the remaining packages.\n",
"\n",
"### Installing with --user option\n",
"If you are using a shared installation of Python (i.e. one installed by the administrator) you will need to add the `--user` option to your `pip install` commands. E.g.\n",
"\n",
"```\n",
"pip install pkg_name --user --upgrade\n",
"```\n",
"\n",
"This will avoid permission errors by installing into your user folder."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script>\n",
" function code_toggle() {\n",
" if ($('div.cell.code_cell.rendered.selected div.input').css('display')!='none'){\n",
" $('div.cell.code_cell.rendered.selected div.input').hide();\n",
" } else {\n",
" $('div.cell.code_cell.rendered.selected div.input').show();\n",
" }\n",
" }\n",
" </script>\n",
"\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"If you answer \"n\" this cell will exit with an error in order to avoid the pip install calls,\n",
"This error can safely be ignored.\n",
"msticpy and Kqlmagic packages are already loaded. Do you want to re-install? (y/n)n\n"
]
},
{
"ename": "SystemExit",
"evalue": "pip install aborted - you may skip this error and continue.",
"output_type": "error",
"traceback": [
"An exception has occurred, use %tb to see the full traceback.\n",
"\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m pip install aborted - you may skip this error and continue.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\ianhelle\\AppData\\Local\\Continuum\\anaconda3\\envs\\condadev\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3275: UserWarning:\n",
"\n",
"To exit: use 'exit', 'quit', or Ctrl-D.\n",
"\n"
]
}
],
"source": [
"import sys\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\",category=DeprecationWarning)\n",
"\n",
"MIN_REQ_PYTHON = (3,6)\n",
"if sys.version_info < MIN_REQ_PYTHON:\n",
" print('Check the Kernel->Change Kernel menu and ensure that Python 3.6')\n",
" print('or later is selected as the active kernel.')\n",
" sys.exit(\"Python %s.%s or later is required.\\n\" % MIN_REQ_PYTHON)\n",
"\n",
"# Package Installs - try to avoid if they are already installed\n",
"try:\n",
" import msticpy.sectools as sectools\n",
" import Kqlmagic\n",
" from dns import reversename, resolver\n",
" from ipwhois import IPWhois\n",
" import folium\n",
" \n",
" print('If you answer \"n\" this cell will exit with an error in order to avoid the pip install calls,')\n",
" print('This error can safely be ignored.')\n",
" resp = input('msticpy and Kqlmagic packages are already loaded. Do you want to re-install? (y/n)')\n",
" if resp.strip().lower() != 'y':\n",
" sys.exit('pip install aborted - you may skip this error and continue.')\n",
" else:\n",
" print('After installation has completed, restart the current kernel and run '\n",
" 'the notebook again skipping this cell.')\n",
"except ImportError:\n",
" pass\n",
"\n",
"print('\\nPlease wait. Installing required packages. This may take a few minutes...')\n",
"!pip install msticpy --upgrade\n",
"!pip install Kqlmagic --no-cache-dir --upgrade\n",
"\n",
"# Additional packages used in this notebook.\n",
"!pip install dnspython --upgrade\n",
"!pip install ipwhois --upgrade \n",
"!pip install folium --upgrade\n",
"\n",
"# Uncomment to refresh the maxminddb database\n",
"# !pip install maxminddb-geolite2 --upgrade \n",
"print('To ensure that the latest versions of the installed libraries '\n",
" 'are used, please restart the current kernel and run '\n",
" 'the notebook again skipping this cell.')"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3",
"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.7.1"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -4,13 +4,18 @@ dnspython<=1.16.0
folium<=0.7.0
holoviews<=1.10.7
ipwhois<=1.1.0
ipywidgets>=7.4.2
ipython>=7.2.0
Kqlmagic<=0.1.91
matplotlib<=3.0.0
maxminddb<=1.4.1
maxminddb-geolite2<=2018.703
msticpy<=0.0.66
networkx<=2.2
numpy>=1.15.4
pandas<=0.24.1
requests<=2.21.0
scikit-learn<=0.20.2
seaborn<=0.9.0
typing>=3.6.6
urllib3>=1.24.1