PyCon 2014

Cómo convertir un ordenador en un servidor gracias a Python

Asheesh Laroia , Karen Rustad  · 


Extracto de la transcripción automática del vídeo realizada por YouTube.

hello hi we have a Karen and a she's here on stage and they'll talk to us about how to turn your computer into a server peace welcome why are you behind me okay alright hi I'm Karen I'm a freelance web developer based in Mountain View California

hi I'm a shish I'm a security engineer at Eventbrite in San Francisco yeah I've been bright people in the middle yeah so this is turn your computer into the server it's an introductory level talk and we have three main goals for this talk that

first by the end of it you have a basic understanding of computer networking you believe that if you have a computer that can access the internet you can run a server on it and you have some ideas for how to do so and finally you have faith that you can do

this and not get immediately hacked or have your computer break or anything terribly awful bad happen so there are two parts of this talk the first part is about simple sharing sharing in progress work or files from your work computer either within a given

network or across networks and part two we'll talk about home servers which is a case where you want it to be up basically all the time versus just one-off connections and these specific considerations associated with that use case so let's imagine

a scenario you're building your first web application in let's say Django and you run your going through the tutorial you run the built-in web server command and the tutorial tell you to go to this localhost colon 8080 in fact you're so excited

and I may or may not have done this myself you quickly copy and paste the link and send it to your roommate to show off your work of course you quickly realize this isn't going to work local host that only works on my computer it's not going to be

seen by anybody else so okay well you get clever you're like well I know the name of my computer like and so I'll replace localhost with my computer at local in the URL and that's going to work right well not exactly and so your roommate still

can't see your Django application that you wanted to show off to them so to figure out why that didn't work and how to fix it we're gonna look at a different tool for basic local sharing which is called simple HTTP server this is a module built

into built-in comes with Python you have it on your computer if you have Python and the way that you use it is you go into a given directory you run this command and the files within that directory will be served by default on port 8000 you can specify the

port and this is a really useful tool for viewing and sharing front-end projects HTML CSS JavaScript or basic file sharing and what's neat about it is it doesn't just work at localhost colon 8080 v'n at my computer that local colon 8000 so this

works but the django built-ins server doesn't so let's compare the two and figure out how we can make the django built-in server act like this simple HTTP server so when we look at the log message that we get when we run the simple HTTP server we get

serving HTTP ad on 0 dot 0 dot 0 to 0 port 8000 and I don't really know what this 4 zeros thing but when I compare it to the Django log message that I get there's a bunch of stuff and it says it's serving at it doesn't have

whatever that is well you might try something clever and in the run server command instead of just specifying the port you might try putting the four zero thing in front of it so it looks like this and in the log message you can see that it's no longer

serving at one to seven it's serving at 0.0 that's 0 that's 0 cool so once you do that you experiment you ask your roommate to try again at my computer at local and they see what you see they see your Gengo application that's pretty cool it

works but we still don't know why or what which I'm really sick of saying means so to explain we need to discuss a talk about a bit about how ports and interfaces work in computer networking you might already be familiar with ports might have

heard them heard of them at least it's easy to conceptualize them as these gateways these entry ways into your computer they're numbered numbered 1 through over 60,000 and so they're not all drawn here and different applications will listen or

bind to different ports and so we know Django is listening to port 8000 and so it's listening for requests to come in from outside the computer and sending responses more or less so that's sort of our basic model of what ports are the reality is actually

a little bit more complicated because you don't just have ports you also have interfaces so it really looks more something like this these what an interface is is a way that your computer gets online so here this computer has three interfaces there's

W land 2 which is your wireless card there's ETH one which is your Ethernet connection and then there's ello which is local loopback which is sort of a virtual interface you can't actually connect to it from outside it only works inside your computer

and so each of these interfaces have their own Bank of ports you don't just have one port 8000 you have in this case 3 you can see what interfaces your computer has and some information about them if you run the command ifconfig on the command line on

most unix c systems and that will give you some useful information about your computer so we can see here that the reason why with the default django run server setup your roommate wasn't able to see it by default that only binds to port 8000 on the local

loopback interface what you're able to access via localhost but when your roommate tries their connecting over the Wi-Fi it's checking a completely different port 8000 and nothing's listening there so they're not able to connect what the

shorthand means is bind to this port on all available interfaces and so Gengo does so and now you can connect over localhost and your roommate can connect over Wi-Fi and you had people connected on Ethernet they could get there - pretty cool so great we've

accomplished our first goal we can show off our work and show off how awesome your django programming skills are to your roommate or anyone else who happens to be on the same network but we've lots of friends who don't live with us who don't share

our Wi-Fi who are elsewhere on the internet that we also want to show off - and so we need different tools to be able to communicate with them in order to understand both to understand how to do this we need to first discuss IP addresses Internet Protocol

addresses these are what are used for routing on the internet and there's two kinds the first is private IP addresses which exist within a given network so if we imagine that this is your network at home there's your Wi-Fi router and there's you

and your roommate and then the router is standing between you and the rest of the Internet private IP addresses only apply on the left side of the diagram between you and the router certain IP address blocks are assigned to be private ID private addresses

so if you see an address that starts with 192.168 or was a 172 dot some stuff or 10 dot stuff that means you're looking at a private address not a public address and you can find out what your computer's private IP address enum is a number of ways

if config will tell you for one another way is using our simple HTTP server that we were doing before when you run it and you access it over localhost when you look at the log message in the terminal window you'll see one thing you'll see a connection

from from localhost but when you connect over my computer dot local instead you'll see something else in the logs you'll see one seven two in this case dot two seven zero at 14 and that is your private IP address on the network you're

currently connected to so that's pretty cool and that means that you could see your roommates private IP address too if they connect over the service you'll see a different IP address belonging to your roommate show up there yeah so that's private

IP addresses thanks Karen I want to talk a little bit about public services so websites like Eventbrite we don't just want to be available inside the office we want them to be reachable from all over the world presumably same with the kind of websites

that you guys want to work on also and to make that happen you need to talk up we need to talk about public IP addresses which are IP addresses that will route from anywhere on the internet so Karin mentioned that IP addresses are what the internet routes

messages based on which means that if you type in something like into your browser then your browser has to first look up what the address is of lucam so that it can send a message to Google and have the web conversation to show you the webpage

[ ... ]

Nota: se han omitido las otras 4.512 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.