Created
November 21, 2013 20:49
-
-
Save econchick/7589366 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "metadata": { | |
| "name": "" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "import nmap" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 1 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "nm = nmap.PortScanner()" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 2 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "spotify = nm.scan('dev.lynn.cloud.spotify.net', '22-443')" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 3 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "roguelynn = nm.scan('roguelynn.com', '22-443')" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 13 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "host_ip = roguelynn['scan'].keys()" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 14 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "roguelynn_hosts = nm.all_hosts()\n", | |
| "print roguelynn_hosts\n", | |
| "#spotify_hosts = nm.all_hosts()\n", | |
| "#print spotify_hosts" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "[u'81.28.232.189']\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 15 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "import select as s\n", | |
| "\n", | |
| "import geojson\n", | |
| "import pygeoip\n", | |
| "from scapy.all import *" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 16 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "def trace_route(ips):\n", | |
| " traceroute_list = []\n", | |
| " for ip in ips:\n", | |
| " traced_ip = []\n", | |
| " try:\n", | |
| " ans, unans = traceroute(ips, maxttl=20)\n", | |
| " for i in xrange(len(ans.res)):\n", | |
| " if ip == ans.res[i][0].dst:\n", | |
| " traced_ip.append(ans.res[i][1].src)\n", | |
| " traced_ip.append(ip)\n", | |
| " traceroute_list.append(traced_ip)\n", | |
| " except s.error:\n", | |
| " continue\n", | |
| " return traceroute_list" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 17 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "def map_ip(tr):\n", | |
| " gip = pygeoip.GeoIP('data/GeoLiteCity.dat')\n", | |
| " coordinates = []\n", | |
| " for route in tr:\n", | |
| " hops = []\n", | |
| " for hop in route:\n", | |
| " geo_data = gip.record_by_addr(hop)\n", | |
| " if geo_data:\n", | |
| " lat = geo_data['latitude']\n", | |
| " lon = geo_data['longitude']\n", | |
| " hops.append((lon, lat))\n", | |
| " coordinates.append(hops)\n", | |
| "\n", | |
| " return coordinates" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 18 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "def create_geojson(coordinates):\n", | |
| " geo_list = []\n", | |
| " j = 1\n", | |
| " for route in coordinates:\n", | |
| " data = {}\n", | |
| " data[\"type\"] = \"Feature\"\n", | |
| " data[\"id\"] = j\n", | |
| " data[\"properties\"] = {\"title\": \"hop %i\" % j}\n", | |
| " data[\"geometry\"] = {\"type\": \"LineString\", \"coordinates\": route}\n", | |
| " j += 1\n", | |
| " geo_list.append(data)\n", | |
| "\n", | |
| " d = {\"type\": \"FeatureCollection\"}\n", | |
| " for item in geo_list:\n", | |
| " d.setdefault(\"features\", []).append(item)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 19 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "tr = trace_route(roguelynn_hosts)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "\n", | |
| "Received 9 packets, got 9 answers, remaining 11 packets\n", | |
| " 81.28.232.189:tcp80 \n", | |
| "12 81.28.232.189 SA \n", | |
| "13 81.28.232.189 SA \n", | |
| "14 81.28.232.189 SA \n", | |
| "15 81.28.232.189 SA \n", | |
| "16 81.28.232.189 SA \n", | |
| "17 81.28.232.189 SA \n", | |
| "18 81.28.232.189 SA \n", | |
| "19 81.28.232.189 SA \n", | |
| "20 81.28.232.189 SA \n", | |
| "Begin emission:\n", | |
| "Finished to send 20 packets.\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 20 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "coordinates = map_ip(tr)\n", | |
| "print coordinates" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "[[(9.0, 51.0), (9.0, 51.0), (9.0, 51.0), (9.0, 51.0), (9.0, 51.0), (9.0, 51.0), (9.0, 51.0), (9.0, 51.0), (9.0, 51.0), (9.0, 51.0)]]\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 25 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "create_geojson(coordinates)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 27 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment