The Internet by Jessica McKellar

The Internet by Jessica McKellar

Afcfefa1f067d10bd021de0cc2e5e806?s=128

PyCon 2013

March 17, 2013
Tweet

Transcript

  1. The Internet @jessicamckellar http://jesstess.com

  2. You type http://python.org into your browser bar and press Enter.

    What happens?
  3. None
  4. Questions What Where How is python.org? is python.org? does my

    computer talk to python.org? does my computer say to python.org? What
  5. Protocol A format and rules for exchanging information

  6. Internet protocols are layered, one protocol per task

  7. What is python.org? Domain Name Service (DNS) translates hostnames to

    addresses python.org → 82.94.164.162
  8. None
  9. Where is python.org? Internet Protocol (IP) handles addressing and routing

  10. Your packets of data hop from router to router through

    the Internet to their destination
  11. scapy demo!

  12. None
  13. >>> res, _ = traceroute("python.org") Begin emission:*.*.*.*.*.*.*.*.*.*.*. 82.94.164.162:tcp80 1 192.168.1.1

    2 96.120.66.81 3 68.85.160.37 4 68.85.106.29 5 68.86.90.57 6 68.86.85.22 7 75.149.228.126 8 134.222.226.154 9 134.222.231.148 10 134.222.231.156 11 134.222.229.113 12 134.222.97.18 13 194.109.5.82 14 194.109.12.34 15 82.94.164.162 >>> res.graph(target="> traceroute.svg") openwrt.lan 96.120.168.1.1 cambridge.ma.boston.comcast.net needham.ma.boston.comcast.net newyork.ny.ibone.comcast.net 111eighthave.ny.ibone.comcast.net nyk-s2-rou-1001.us.eurorings.net ldn-s2-rou-1101.uk.eurorings.net ldn-s1-rou-1021.uk.eurorings.net asd2-rou-1022.nl.eurorings.net asd2-rou-1044.nl.eurorings.net 134.222.97.18 xr4.1d12.xs4all.net swcolo2.3d12.xs4all.net dinsdale.python.org
  14. Me python.org

  15. Me

  16. None
  17. None
  18. python.org

  19. traceroute_ips = """ 96.120.66.81 68.85.160.37 68.85.106.29 68.86.90.57 68.86.85.22 75.149.228.126 134.222.226.154

    134.222.231.148 134.222.231.156 134.222.229.113 134.222.97.18 194.109.5.82 194.109.12.34 82.94.164.162 """.strip().split("\n")
  20. import pygeoip gi = pygeoip.GeoIP("GeoLiteCity.dat") for ip in traceroute_ips: record

    = gi.record_by_addr(ip) print ip.ljust(15), print record["country_name"], if record["time_zone"]: print record["time_zone"], print ""
  21. $ python geolocate.py 96.120.66.81 United States Boston 68.85.160.37 United States

    Boston 68.85.106.29 United States Boston 68.86.90.57 United States New_York 68.86.85.22 United States New_York 75.149.228.126 United States New_York 134.222.226.154 United Kingdom London 134.222.231.148 United Kingdom London 134.222.231.156 Netherlands Amsterdam 134.222.229.113 Netherlands Amsterdam 134.222.97.18 Netherlands Amsterdam 194.109.5.82 Netherlands Amsterdam 194.109.12.34 Netherlands Amsterdam 82.94.164.162 Netherlands Amsterdam
  22. http://submarinecablemap.com

  23. None
  24. Where is python.org? Internet Protocol (IP) IP handles addressing and

    routing
  25. How does my computer talk to python.org? Transmission Control Protocol

    (TCP) TCP reliably delivers data
  26. None
  27. Application-layer protocols that use TCP web: HTTP chat: IRC, XMPP/Jabber

    email: SMTP, POP3, IMAP Each application uses a different “port” number, so many different applications can use TCP to talk to an IP address at the same time
  28. How does my computer talk to python.org? Transmission Control Protocol

    (TCP) TCP reliably delivers data
  29. What does my computer say to python.org? HyperText Transfer Protocol

    (HTTP) Clients use HTTP to request resources from servers
  30. Resources • HTML • images • textual or binary data

    • dynamically-generated query results ://python.org http
  31. How to be a web browser telnet demo!

  32. None
  33. $ telnet python.org 80 Trying 82.94.164.162... Connected to python.org. Escape

    character is '^]'. GET / HTTP/1.1 Host: python.org
  34. HTTP/1.1 200 OK Date: Mon, 04 Mar 2013 00:22:30 GMT

    Server: Apache/2.2.16 (Debian) Last-Modified: Fri, 01 Mar 2013 22:31:40 GMT Content-Type: text/html <head> <title> Python Programming Language &ndash; Official Website </title> </head>
  35. HTTP/1.1 200 OK Date: Mon, 04 Mar 2013 00:22:30 GMT

    Server: Apache/2.2.16 (Debian) Last-Modified: Fri, 01 Mar 2013 22:31:40 GMT Content-Type: text/html <head> <title> Python Programming Language &ndash; Official Website </title> </head>
  36. HTTP/1.1 200 OK Date: Mon, 04 Mar 2013 00:22:30 GMT

    Server: Apache/2.2.16 (Debian) Last-Modified: Fri, 01 Mar 2013 22:31:40 GMT Content-Type: text/html <head> <title> Python Programming Language &ndash; Official Website </title> </head>
  37. HTTP/1.1 200 OK Date: Mon, 04 Mar 2013 00:22:30 GMT

    Server: Apache/2.2.16 (Debian) Last-Modified: Fri, 01 Mar 2013 22:31:40 GMT Content-Type: text/html <head> <title> Python Programming Language &ndash; Official Website </title> </head>
  38. HTTP/1.1 200 OK Date: Mon, 04 Mar 2013 00:22:30 GMT

    Server: Apache/2.2.16 (Debian) Last-Modified: Fri, 01 Mar 2013 22:31:40 GMT Content-Type: text/html <head> <title> Python Programming Language &ndash; Official Website </title> </head>
  39. import urllib2 urllib2.urlopen( "http://python.org").read() HyperText Transfer Protocol HyperText Markup Language

    Scrapy: it GETs the Web
  40. How to be a web server

  41. class HTTPProtocol(basic.LineReceiver): def __init__(self): self.lines = [] def lineReceived(self, line):

    self.lines.append(line) if not line: self.sendResponse() def sendResponse(self): self.sendLine("HTTP/1.1 200 OK") self.sendLine("") for line in self.lines: self.sendLine(line) self.transport.loseConnection() reactor.listenTCP(80, HTTPFactory()) reactor.run() Twisted HTTP echo server
  42. class HTTPProtocol(basic.LineReceiver): def __init__(self): self.lines = [] def lineReceived(self, line):

    self.lines.append(line) if not line: self.sendResponse() def sendResponse(self): self.sendLine("HTTP/1.1 200 OK") self.sendLine("") for line in self.lines: self.sendLine(line) self.transport.loseConnection() reactor.listenTCP(80, HTTPFactory()) reactor.run()
  43. GET / HTTP/1.1 Host: localhost:80 Connection: keep-alive Accept: text/html,application/xhtml +xml,application/xml;q=0.9,*/*;q=0.8

    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/ 537.17 (KHTML, like Gecko) Chrome/ 24.0.1312.57 Safari/537.17 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 What your browser sends web servers
  44. What does my computer say to python.org? HyperText Transfer Protocol

    (HTTP) Clients use HTTP to request resources from servers
  45. You type http://python.org into your browser bar and press Enter.

    What happens?
  46. IP IP TCP TCP HTTP HTTP addressing and routing reliable

    delivery requesting resources DNS DNS hostnames → IP addresses
  47. <wireshark demo>

  48. None
  49. Surfing the web protocol source IP destination IP protocol data

  50. Lonely printers source IP destination IP protocol protocol data

  51. Lonely TiVos

  52. Errors TCP protocol, retransmitting lost data

  53. Encrypted communication source IP destination IP protocol protocol data

  54. IRC

  55. IRC IRC server prompting for a password

  56. IRC My password, django4life

  57. </wireshark demo>

  58. One last demo How to propose marriage on your local

    network using Scapy and ARP-cache poisoning
  59. Lonely printers Address Resolution Protocol (ARP) maps hardware (MAC) addresses

    to IP addresses
  60. None
  61. What next? •Twisted (visit me at the Expo Hall!) •Scapy

    •wireshark
  62. @jessicamckellar http://jesstess.com Thank you!

  63. A map of the entire Internet in 1977