Python. Network. Marcin Młotkowski. 24th April, 2013



Similar documents
Network Technologies

The Application Layer. CS158a Chris Pollett May 9, 2007.

Lecture 2-ter. 2. A communication example Managing a HTTP v1.0 connection. G.Bianchi, G.Neglia, V.Mancuso

Data Communication I

TCP/IP Networking An Example

1. When will an IP process drop a datagram? 2. When will an IP process fragment a datagram? 3. When will a TCP process drop a segment?

The Web: some jargon. User agent for Web is called a browser: Web page: Most Web pages consist of: Server for Web is called Web server:

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

Network Configuration Settings

1. The Web: HTTP; file transfer: FTP; remote login: Telnet; Network News: NNTP; SMTP.

COMP 112 Assignment 1: HTTP Servers

Outline Definition of Webserver HTTP Static is no fun Software SSL. Webserver. in a nutshell. Sebastian Hollizeck. June, the 4 th 2013

1 Introduction: Network Applications

Lepide Active Directory Self Service. Configuration Guide. Follow the simple steps given in this document to start working with

World Wide Web. Before WWW

Divide and Conquer Real World Distributed Port Scanning

Modern Web Development From Angle Brackets to Web Sockets

LESSON Networking Fundamentals. Understand TCP/IP

Chapter 11. User Datagram Protocol (UDP)

Chapter 6 Configuring the SSL VPN Tunnel Client and Port Forwarding

Computer Networks. Lecture 7: Application layer: FTP and HTTP. Marcin Bieńkowski. Institute of Computer Science University of Wrocław

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Owner of the content within this article is Written by Marc Grote

Chapter 27 Hypertext Transfer Protocol

Protocolo HTTP. Web and HTTP. HTTP overview. HTTP overview

THE PROXY SERVER 1 1 PURPOSE 3 2 USAGE EXAMPLES 4 3 STARTING THE PROXY SERVER 5 4 READING THE LOG 6

Basic Networking Concepts. 1. Introduction 2. Protocols 3. Protocol Layers 4. Network Interconnection/Internet

Cyber Security Workshop Ethical Web Hacking

Web Programming. Robert M. Dondero, Ph.D. Princeton University

File Transfer And Access (FTP, TFTP, NFS) Chapter 25 By: Sang Oh Spencer Kam Atsuya Takagi

First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring

Linux MDS Firewall Supplement

Web Browsing Examples. How Web Browsing and HTTP Works

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

No. Time Source Destination Protocol Info HTTP GET /ethereal-labs/http-ethereal-file1.html HTTP/1.

Deployment Guide Microsoft IIS 7.0

APACHE WEB SERVER. Andri Mirzal, PhD N

DEPLOYMENT GUIDE Version 1.1. Deploying the BIG-IP LTM v10 with Citrix Presentation Server 4.5

CIT 380: Securing Computer Systems

EXPLORER. TFT Filter CONFIGURATION

Principles of Network Applications. Dr. Philip Cannata

Introduction to Computer Networks

Open Thunderbird. To set up an account in Thunderbird, from the Tools menu select Account Settings; choose account; then click Next.

12. Firewalls Content

User Datagram Protocol - Wikipedia, the free encyclopedia

APACHE HTTP SERVER 2.2.8

How to Make the Client IP Address Available to the Back-end Server

INTRODUCTION NETWORK SOCKETS

Linux MPS Firewall Supplement

CS640: Introduction to Computer Networks. Applications FTP: The File Transfer Protocol

Communicating Applications

EE4607 Session Initiation Protocol

HTTP Protocol. Bartosz Walter

Cisco Configuring Commonly Used IP ACLs

CHARTER BUSINESS custom hosting faqs 2010 INTERNET. Q. How do I access my ? Q. How do I change or reset a password for an account?

Python Network Programming

The exam has 110 possible points, 10 of which are extra credit. There is a Word Bank on Page 8. Pages 7-8 can be removed from the exam.

Pyak47 - Performance Test Framework. Release 1.2.1

Configuring Security for FTP Traffic

HTML5 Websockets with ruby and rails. Saurabh Bhatia, CEO, Safew Labs

What is Distributed Annotation System?

Update Instructions

Sticky Session Setup and Troubleshooting

Lektion 2: Web als Graph / Web als System

Distributed Systems. 2. Application Layer

Firewall VPN Router. Quick Installation Guide M73-APO09-380

Elluminate Live! Access Guide. Page 1 of 7

Summer Internship 2013

AnyConnect VPN Client FAQ

RC2000 Web Server User s Manual RCI P/N: FP-SER-ETH-SERVR1

Computer Networks. Examples of network applica3ons. Applica3on Layer

Exercises: FreeBSD: Apache and SSL: pre SANOG VI Workshop

Multi-Homing Dual WAN Firewall Router

Cape Girardeau Career Center CISCO Networking Academy Bill Link, Instructor. 2.,,,, and are key services that ISPs can provide to all customers.

HTTP. Internet Engineering. Fall Bahador Bakhshi CE & IT Department, Amirkabir University of Technology

Secure Outgoing Mail (SMTP) Setup Guide

Update Instructions

Figure 41-1 IP Filter Rules

Remote Connectivity to XV, XP and epro units running Visual Designer

Update Instructions

Detailed Table of Contents

How To Configure SSL VPN in Cyberoam

Domain Name System (DNS)

GS-AN045 S2W UDP, TCP, HTTP CONNECTION MANAGEMENT EXAMPLES

Table of Contents. Open-Xchange Authentication & Session Handling. 1.Introduction...3

Configuring MassTransit Server to listen on ports less than 1024 using WaterRoof on Macintosh Workstations

CPSC Network Programming. , FTP, and NAT.

CPS221 Lecture: Layered Network Architecture

File Transfer Protocol (FTP) & SSH

SSL VPN. Virtual Private Networks based on Secure Socket Layer. Mario Baldi. Politecnico di Torino. Dipartimento di Automatica e Informatica

Application Detection

SSL VPN connection multiplexing techniques

WHAT IS A WEB SERVER?

Client Configuration Secure Socket Layer. Information Technology Services 2010

OCS Training Workshop LAB14. Setup

Project #2. CSE 123b Communications Software. HTTP Messages. HTTP Basics. HTTP Request. HTTP Request. Spring Four parts

Transcription:

Network 24th April, 2013

1 Transport layer 2 3 4

Network layers HTTP, POP3, SMTP, FTP Transport layer TCP, UDP Internet

User Datagram Protocol (UDP) Features of UDP Very easy Unreliable: no acknowledgment, retransmission or timeout. Used generally in local (reliable) networks Communication based on sockets

Example Transport layer Task Send from client s host to server a message "Hello ".

Client Transport layer Implementation import socket port = 8081 host = localhost s = socket.socket(socket.af_inet, socket.sock_dgram) s.sendto( Hello,!!!, (host, port))

Receiver Transport layer Implementation import socket port = 8081 s = socket.socket(socket.af_inet, socket.sock_dgram) s.bind((, port)) print Listening port, port while True: data, addr = s.recvfrom(1024) print Sender, addr, data, data

Sockets Transport layer Other functions provided by socket: gethostname() host name gethostbyname(hostname) IP of host gethostbyaddr(ip_address) SSL

Advanced task How to monitor remote computers by a web browser Each computer runs a special http server; each request triggers an action, e.g.: http://host/uptime runs a command uptime and sends a result to web browser; default action: a list of available functions.

Some details of http protocol: request Client GET / HTTP/1.1 Host: www.ii.uni.wroc.pl User-Agent: Mozilla/5.0

Some details of http protocol, response Server HTTP/1.1 200 OK Date: Mon, 21 Dec 2009 09:14:01 GMT Server: Apache/2.0.54 (Debian GNU/Linux) Content-Length: 37402 <data>

HTTP request processing Web server: an object of the class BaseHTTPServer.HTTPServer supports http needs an object which now how to deal with different types of requests

HTTP request processing Web server: an object of the class BaseHTTPServer.HTTPServer supports http needs an object which now how to deal with different types of requests Request processing: a class BaseHTTPRequestHandler abstract class methods processing requests like GET, POST, HEADER,... helpers to create responses

Server Transport layer Implementation from BaseHTTPServer import * import os class MyHttpHandler(BaseHTTPRequestHandler):

MyHttpHandler implementation Processing GET request def do_get(self): self.send_response(200) self.send_header( Content-type, text/html ) self.end_headers() self.wfile.write( <html><head></head> ) self.wfile.write( <body> ) if self.path == /uptime : self.uptime() else : self.menu() self.wfile.write( </body></html> ) self.wfile.close()

Server implementation uptime implementation def uptime(self): res = os.popen( uptime ).read() self.wfile.write( <h1>result of uptime</h1> ) self.wfile.write( <tt> + res + </tt> )

Server implementation Menu def menu(self): self.wfile.write( <h1>server</h1> ) self.wfile.write( <ul> ) self.wfile.write( <li><a href="uptime">uptime</a></li> ) self.wfile.write( </ul> )

Http server Start the server address = (, 8000) httpd = BaseHTTPServer.HTTPServer(address, MyHttpHandler) httpd.serve_forever()

Client HTTP import httplib class browser: def init (self): h = self.request( computer12, GET, /uptime/ ) resp = h.getresponse() print Kod, resp.status print resp.read()

Client HTTP import httplib class browser: def init (self): h = self.request( computer12, GET, /uptime/ ) resp = h.getresponse() print Kod, resp.status print resp.read() Preparing request def request(self, host, method, page): headers = { Host : host, Accept : text/html } h = httplib.httpconnection(host) h.request(method, page,, headers) return h

http client Transport layer Run client browser()

Batteries Included Standard libraries ftplib, poplib, mmtplib, nntplib, email, mimetools, mimetypes, base64

Batteries Included Standard libraries ftplib, poplib, mmtplib, nntplib, email, mimetools, mimetypes, base64 For pirates TinyP2P

Transport layer foo(args) wynik

Used protocols General InterORB Protocol Remote Java Invocation RPC.NET Remoting XML RPC...

Task Transport layer A server computing nth Fibonacci number

Server Transport layer Implementation def fib(n): if n < 2: return 1 return fib(n - 1) + fib(n - 2)

Server Transport layer Implementation def fib(n): if n < 2: return 1 return fib(n - 1) + fib(n - 2) Server implementation from SimpleXMLRPCServer import * server = SimpleXMLRPCServer(( localhost, 8002)) server.register_function(fib) server.register_function(lambda x, y: x + y, add ) server.serve_forever()

Client Transport layer Implementation import xmlrpclib server = xmlrpclib.server( http://localhost:8002 ) print server.fib(10) print server.add(2,3)

SOAP Transport layer Simple Object Access Protocol Extension of XML-RPC W3C standard No library in standard distribution of Independent distribution SOAP, eg. SOAPPy

SOAP services Public services in SOAP Google Amazon Allegro

Multithreading server How to do that?

Solution Transport layer Mix-in classes SocketServer.ThreadingMixIn SocketServer.ForkingMixIn

import SocketServer from SimpleXMLRPCServe import SimpleXMLRPCServer

import SocketServer from SimpleXMLRPCServe import SimpleXMLRPCServer class AsyncServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer): pass server = AsyncServer((, 8002))

import SocketServer from SimpleXMLRPCServe import SimpleXMLRPCServer class AsyncServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer): pass server = AsyncServer((, 8002)) server.register_function(foo) server.serve_forever()