CS214 - Advanced UNIX

Similar documents
LECTURE 10. Networking

The Application Layer: Sockets Wrap-Up

The Application Layer: Sockets Wrap-Up

4.5 Accessing Networks

Network Programming in Python. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

UseNet and Gossip Protocol

Network Security. Introduction to networks. Radboud University, The Netherlands. Autumn 2015

A set of processes distributed over a network that communicate via messages. Processes communicate via services offered by the operating system

SOCKET. Valerio Di Valerio

Interprocess communication in shared memory systems. Interprocess communcation. Berkeley Sockets

Computer Networks Prof. Ashok K. Agrawala

The Application Layer: Sockets Wrap-Up

Interprocess communcation

Networking. Chapter How to identify machines on internet Ports

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

Basics. Once socket is configured, applica6ons. Socket is an interface between applica6on and network

Fundamentals of Linux Platform Security

Fundamentals of Linux Platform Security. Hands-On Network Security. Roadmap. Security Training Course. Module 1 Reconnaissance Tools

9th Slide Set Computer Networks

Modules. The highest level structure of Python Each file with the.py suffix is a module Each module has its own namespace

4D WebSTAR V User Guide for Mac OS. Copyright (C) D SA / 4D, Inc. All rights reserved.

Networked Applications: Sockets. End System: Computer on the Net

SOCKET PROGRAMMING. What is a socket? Using sockets Types (Protocols) Associated functions Styles

Lecture 2. Outline. Layering and Protocols. Network Architecture. Layering and Protocols. Layering and Protocols. Chapter 1 - Foundation

Python can be simple. Introduction to Python. Alternative import. Python Modules allow for problem decomposition

Lecture 3: The Domain Name System and Sockets

CS 395-0, Section 22 Project Part B Dinda, Fall TCP for Minet. Project Part B

Python While Loop. if statement and functions. Python Functions. #!/usr/bin/python

The Swiss Army Knife netcat

Users Guide. Kerio Technologies

John Romero Programming Proverbs

IBM AIX Operating System Courses

Problem Set 4 Due: Start of class, October 5

Netcat Scanning to Backdoors

Introduction to Python Network Programming for Network Architects and Engineers

Sockets 15H2. Inshik Song

CPS 214: Computer Networks. Slides by Adolfo Rodriguez

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Lab Assignment 3 for ECE374

CSC209 Review. Yeah! We made it!

netcat Johannes Franken

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Computer Systems and Networks

Wget A Noob s guide. Wget is a command line application for retrieving content from web servers.

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

Tutorial on Socket Programming

Internet Connectivity with

General Network Troubleshooting

Tutorial on Network Programming with Python

transmission media and network topologies client/server architecture layers, protocols, and sockets

C18: Network Fundamentals and Reliable Sockets

Wireless and Dorm Printing Overview

Socket Programming for TCP and UDP

ECE 650 Systems Programming & Engineering. Spring 2018

Foundations of Python

Confinement (Running Untrusted Programs)

AxiCat Server. v User Manual

Types (Protocols) Associated functions Styles We will look at using sockets in C Java sockets are conceptually quite similar

Distributed Systems. 02. Networking. Paul Krzyzanowski. Rutgers University. Fall 2017

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

A Client-Server Exchange

Session NM056. Programming TCP/IP with Sockets. Geoff Bryant Process software

OSI Model with Protocols. Layer Name PDU Address Protocols Device

IPv6 LAB. Practical IPv6. Alvaro Vives 27 June 2017 Workshop on Open Source Solutions for the IoT

Features of Netcat. Abstract. Keywords. I. Introduction. II. History. Jeffrey Kurcz School of Computer Science University of Windsor

ECE 435 Network Engineering Lecture 2

Overview. Exercise 0: Implementing a Client. Setup and Preparation

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Outline. Operating System Security CS 239 Computer Security February 23, Introduction. Server Machines Vs. General Purpose Machines

(Worth 50% of overall Project 1 grade)

The Application Layer: Sockets, DNS

Full Stack Web Framework with BBG

LPR for Windows 95/98/Me/2000 TCP/IP Printing User s Guide

Contents: 1 Basic socket interfaces 3. 2 Servers 7. 3 Launching and Controlling Processes 9. 4 Daemonizing Command Line Programs 11

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Using the SSM Administration Console

CSE 333 Lecture server sockets

CSE 124 January 18, Winter 2017, UCSD Prof. George Porter

Data Security and Privacy. Unix Discretionary Access Control

Taken from the README of the netcat source tree, this description sums up the uses of netcat perfectly.

Basic Linux Command Line Interface Guide

CS UDP: User Datagram Protocol, Other Transports, Sockets. congestion worse);

Basic Linux Command Line Interface Guide

Overview. Exercise 0: Implementing a Client. Setup and Preparation

CompTIA Exam LX0-102 Linux Part 2 Version: 10.0 [ Total Questions: 177 ]

15-Minute Linux DFIR Triage. Dr. Phil Polstra Bloomsburg University of Pennsylvania

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

Lecture 24. Thursday, November 19 CS 375 UNIX System Programming - Lecture 24 1

LECTURE WK4 NETWORKING

Python Networking Chris Seddon

Transport Layer (TCP/UDP)

Fiery PRO 80 /S450 65C-KM Color Server. Printing from Windows

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme

Network Programming. ò Network Protocols ò Communication Connection ò Naming

Exercises: Basics of Networking II Experiential Learning Workshop

Socket Programming HOWTO Release 3.5.1

Transcription:

CS214 - Advanced UNIX Lecture 10 - Networking continued. Documents Uses material from Ymir Vigfusson The Python Documentation (http://docs.python.org) CS214 p. 1

Privileges Recall that UNIX has a superuser root with UID (user-id) 0. Provides privilege separation for: File system. Can t access or execute folders or files that you don t own unless granted permission. Processes. Can t signal or intercept other processes. CS214 p. 2

Privileges Device drivers, including graphics and sound cards. Kernel communication. Unauthorized for many of commands. Sockets. Can t open a port below 1024. (leaves 1025-65535). CS214 p. 3

Wget wget is a wonderful automatic network downloader Example: wget http://www.google.com/ will grab index.html into the current folder. wget -r tries to recurse directories, useful for producing a local mirror of a site. Use -nd to omit creating a local directory structure. wget -c resumes an earlier download, say if power went out while retrieving a large file. CS214 p. 4

UNIX networking commands nslookup, host and dig are utilities for interacting with DNS servers. If you re feeling amibitious, tcpdump -n will list all network traffic that is received by the network interface card. CS214 p. 5

UNIX networking commands Making your own client and server. The nc (netcat) utility is handy for connecting and receiving data on arbitrary ports. nc -vlp 5000 -c./script will listen on port 5000 for a connection, and execute script as a server. netstat -ap will give you a list of local network connections and open ports, along with each responsible process. CS214 p. 6

Sockets in bash Recent versions of bash allow scripts to connect to arbitrary places using the /dev/tcp interface. It s disabled on Debian/Ubuntu per default. exec 3<>/dev/tcp/www.cornell.edu/80 echo "GET / HTTP/1.0" >&3 cat <&3 CS214 p. 7

Socket primitives Initially, low-level communication code can look intimidating. Not fundamentally complex things going on. For clients we want to get a socket, connect it to a remote host, and communicate. For servers, we want to bind a socket to a port, listen for clients, accept them and then communicate. CS214 p. 8

Socket primitives in Python First must import socket. Get a TCP socket using s=socket.socket(af_inet,sock_stream). UDP would use SOCK_DGRAM instead. Local UNIX sockets for inter-process communication would use AF_UNIX. CS214 p. 9

Client code in Python Then connect to a server. Use s.connect((host,port)). Note use of tuple. For example, s.connect(( www.google.com,80)). Python is nice about resolving DNS names for you and saves you a headache about network byte order (endianness). CS214 p. 10

Client code in Python Data is sent using s.send( text ) Request is received using buf = s.recv(1024) (or any arbitrary size). CS214 p. 11

Client code in Python Reading and writing can be made more convenient by transforming the socket into a file. f = s.makefile( rw, 0) accomplishes this. Now you can do e.g. f.write(f.readline().strip()). Remember to close both the file and socket using f.close() and s.close(). CS214 p. 12

Client in Python from socket import * s = socket(af_inet, SOCK_STREAM) s.connect(( keegatahw.com, 5000)) s.send( Hello, world ) data = s.recv(1024) s.close() print Received, repr(data) CS214 p. 13

Server in Python For servers, we still open up a socket s We then bind the socket to a port. s.bind((host,port)) where host is usually just for the current hostname. s.listen(1) will allow a backlog of at least 1 client (system max. 5) to wait for the port. CS214 p. 14

Server in Python For non-intuitive reasons, we often use c.setsockopt(socket.sol_socket, socket.so_reusea This allows ports to be reused even though active TCP connections are still timing out. CS214 p. 15

Server in Python We can now wait for a client by calling accept conn,addr = s.accept() Here conn is a socket for that particular client. addr is a structure containing the remote IP address, and some other useful information about the client. CS214 p. 16

Server in Python We can now communicate with conn like we did with the s socket in the client. What if we wish to use non-blocking routines? We use select like in C. CS214 p. 17

Non-blocking sockets First use s.setblocking(0) ready_to_read, ready_to_write, in_error = select.select(potential_readers, potential_writers, potential_errs, timeout) CS214 p. 18

Server in Python from socket import * s = socket.socket(af_inet, SOCK_STREAM) s.bind((, 5000)) #localhost, port 5000 s.listen(1) conn, addr = s.accept() print Connected by, addr while 1: data = conn.recv(1024) if not data: break conn.send(data) conn.close() CS214 p. 19

Open Office How do you write documents? Open office (ooffice) is an open-source suite based on Sun s commercially developed Star Office. Competitive to other WYSIWYG (what you see is what you get) products, including MS Office. Highly portable, but sometimes slow. CS214 p. 20

L A TEX How do you write pretty documents? T E X written by Stanford professor Donald Knuth to typeset his Art of Computer Programming Books beautifully in 1970s. LAT E X is still the standard of most math, physics and engineering discples. LAT E X is a mark-up language, much like HTML. Documents must be compiled into final output. CS214 p. 21

Viewing documents How do I view them? Plethoria of PS and PDF viewers. gv (ghostview) is based on Ghostscript and has a good renderer for both formats). evince and xpdf work too. Adobe has released their reader for UNIX. CS214 p. 22

Printing What about printing? The line printer daemon lpd is responsible for maintaining a database of printers that you can contact. Use lpr -P printer document to send a document to a printer. Supports various types of servers, from local USB ports to SAMBA to TCP/IP. CS214 p. 23