How To Anonymize Your Python Requests With Tor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone will come back back to computer science and fangs today we're gonna be talking about how to set the tour expert bundle for you to be able to use with Python and Windows 10 so first of all in order to do this we got to go to the tour website here and this is the website right here so we're gonna go to the home page and we're gonna go download tour this is the Royal you want right here so we're gonna go download tour want to view all downloads we're gonna go to Microsoft Windows and we're going to download the tour expert bundle it's gonna click on that and it'll take a second here you're gonna get a zip file that should take about a minute here once you're done downloading the file we're gonna store the file in a location that we're gonna frequently access well first we're gonna unzip it and then we're going to take the information in there and transfer it to a different file location and what tor does basically is it takes your information passes it through different nodes in the tor network and then sends it to the destination server it also encrypts your information by doing an onion system where through each server it encrypts your information over and over which makes it infinitely more difficult to hack into by an exponential amount it's just a good overall service to keep your information hidden from individuals that are nefarious or from people that want to locate your identity by your IP address all right so we've downloaded that file we're gonna go to the Downloads folder real quick let's go to downloads and we're gonna go here and we're gonna unzip it you'll just hit extract all here as you can see I've already downloaded it right here before now if we go back to downloads we can see that this is what we got here now what we want to do is we want to simply double click on this and see what happens on startup and I'm gonna click more info and hit run anyway because we know it store and as you can see we've started the program and as you can see it's listening on port 9050 of our computer which is a Sox listener and then this one right here is a configuration that I've put in here so you're not gonna see that but you are going to see is a where the configuration file is stored right here on the the one two three four fifth line right here you're gonna want to go to here or to this folder that's here my folder is users uka up data roaming tour and then we're gonna configure a torque file here now you can find this torque file by going to documentation and to the general FAQ frequently asked question we're gonna control F torque and we're gonna look for this real quickly here we go advanced tour usage right here and I'm gonna click on the sample torque file page you're gonna come here and you're gonna want to go to this domain right here and download and basically copy and paste this code into a text file so we're gonna copy and paste this code this is just a basic configuration folder with everything commented out so I'm going to store that into a notepad folder right here there we go and we're gonna save that folder where the configuration said that our tour was tour configuration with stores so see right here my configuration says it's stored right here it says read configuration file blah blah blah blah blah okay so we're gonna go to this location here and store this data and save it as t orr c so we're gonna go file save as and we're gonna go to here so we're gonna just copy-paste that and then put this here and copy paste that and then we should be able to just go click on that arrow button there and you see that we are now in this folder here and what you're going to want to do is you're gonna want to save it there as torque but as you can see you just want to save it as this but as you can see I've already stored a folder here named torque now once you've done all that we're gonna talk about the we're gonna you're gonna go to the you're gonna go to once you've saved it to that folder that I just showed you you're gonna go to a line width control port control should be in here somewhere right here control port you're gonna want to uncomment that line and you're also gonna want to uncomment this line and so this isn't allow you to control your connection between you and the Tor network and it's gonna allow you to reset your IP address whenever you want to essentially this password right here is just the hash control password for password itself so when you interact with this control port you pass in the password represented by this hash and it will allow access if it matches this hash now you can change this by simply going to gonna go to the command prompt already to go to der and we're gonna go to CD where we gonna go here we need to go to basically this file right here so we're just gonna go to this file again right here because that's where I've stored my that's also where I've stored my tour execute as well for us right now we only have it stored in the downloads so what you're also gonna want to do is you don't have to go here take this folder control exit and then we're gonna go to this location here and simply save it there I think we were just we did that already now we haven't done that yet so we're gonna go here control see that and we're gonna open a new window here we're gonna say I want a new file explorer window say control-v go to this folder here and we're there and you're gonna say okay I want to control X this and to here and you're gonna do that and it'll it should do it when you run it right now I have tor running so when you copy and paste that over you're gonna want to exit from this program here first so we're gonna cancel that you're gonna cop control V this it's gonna control X control V there and that'll copy and paste it into here and that's just gonna store your tour executable where your configuration files are also stored so you don't have to fumble around looking for where your configuration files are stored where your executable stored and whatnot so forth so we're gonna delete that real quick because I already have my tour executable stored right here but I'm going to do is I'm going to copy and paste this file location here and we're going to change directory to here and then we're going to do tour - - hash - password and we can type in the password that we want to use so like let's say we want to use oh I don't know cool-kid 23 and that would be our password that we want to use whenever we access the control port and we hit enter and this would be the hash that we get so this would be the hatch that matches this string here so we're gonna copy and paste this hash and store it within this folder here and then control V over that now once you've done this you save it and that's how you're going to be that's the password you're gonna use this password you used here that's how you're gonna access the control port in order to change your IP in order to reset your IP and whatnot so forth through the command line through and through Python we're gonna go to basically we're gonna go to here now and I'm gonna show you exactly what we're gonna do now that we have that set up and what we want what you want to start to do is you want to come here come to where your tour executable stored and simply double click it and that will run the torques cutable and now you can see that once you've done this and you set up your torque T oh oh our RC file then you're gonna see that you have a control port set up here and you have the Sox listener here as well and you also have the bootstrapped listening of course and the rest of this you can ignore so we're just gonna minimize that and that's gonna be running in the background essentially that's gonna be running on its own thread what we want to do is we want to come to our Python program here and I'm gonna explain to you this really slowly and really simply so what it's gonna require to do is it's gonna have you require two pip install requests and it's gonna require two you two pip install stem as well so we're gonna come you're gonna come to a different command prompt folder from this one that we already have currently running we're gonna do pip install requests and that should install requests for you I already have it so it says a requirement already satisfied bla bla bla bla bla you know all that fun stuff and it says pip and we did pip install stem and that will install stem for you as you can see my requirements already satisfied but that's gonna get all the requirements that you need essentially just to make sure - I want you to also download a couple more things don't want you to go pip install requests - - upgrade maybe it's upgraded I'm not sure no it's upgrade and that's gonna give you the very most recent version of requests that is available it's gonna give you the development version essentially it's not the stable version but the reason why we want to do that is we want to pip install requests and I think it's socks here for sockets and as you can see I've already downloaded it but once you do that you should be able to have this Sox request Sox library as well and that's just to ensure that everything goes fine for you in the process I think that should be everything that we need here in order to get started so what I'm gonna go through is I'm gonna go and explain this stuff to you word by word now if you want to see basically where I got this coat room I got this coat from this URL here and the title of the stack overflow pages make requests using Python over tor and it's the second solution not the first solution the first solution gives you a very very simple rundown of how to use it the second solution gives you a more in-depth rundown and what basically all this stuff does so you says it tells you to pip install stem but and a lot of it but most of the stuff also too is so like right here this is for Linux users it seems it's more Linux oriented as well anyways if you just follow me I'm going to explain to you everything here what this guy says here so we're gonna come here we're gonna go to the code that I have here and we're going to comment out and if you go to my blog page where I've posted this stuff you're gonna have all the links are necessary for this you're gonna have all the code that's necessary to run this and you'll also be able to copy and paste that into your own folder and be able to follow along here we're going to change that password because we've changed our password to I think it was cool kid 23 or whatever what do we say it was it was cool kid 23 right here so we're gonna take this right here I didn't change my torque file so we're gonna do that real quickly I'm gonna go to my torque file real quickly and so that's right in here I'm gonna go edit with notepad plus plus and I'm gonna change this to my new password I'm gonna save it now I'm going to minimize that in case I have any problems with it I'm going to come to my to my Python folder and we're gonna explain this slowly so I'm gonna slowly go through all this code right here and well actually I want to put my I want to put my password right here and your gonna put your password right here too so what was my password it was a I think it was cool kid 23 good we're cool kids you know kid 23 nice so we've got that set up now what is all this stuff do let's go through very slowly here and so I'm gonna comment this stuff out just so it's easy to tell or what we're looking at so right now we're gonna be looking at this function here this function basically gets a basic tour request session a session essentially creates a connection between it's a session object essentially is a request object that maintains cookies between each request you make to a server so that way you don't have the cookies resetting each time you connect to the server again it also has authentication constants it's basically just an easier way of using requests without having to reset your information every single time and having passed in like authorization each time what not to the server and now these session proxies uses the socks5 protocol and this is essentially proxies that you use through your ports this helps anonymize your your IP and it sets it to where the to where the to the port that tor is currently running out which is 90/50 and that's the default port that tor runs at now if we go and then it returns the session object so this is the basic building function essentially what this does now if we go to this these next few lines here we do alt 4 that's that key binding 2d comment stuff we see we make a request to the Tor connection IP visible through tor this is the we build a session object from our function here and then we print the IP that we get when we go through here and this is the tour this is the Tor IP that we get right here now this is my IP I'm not gonna show you this but you should definitely run this so that way you can see that this this IP right here that you when you run it never actually changes when you use it so and when you run this every time you run this it'll change but we need a little more complexity to it in order to be able to write a program that anonymizes Rp directly we also don't want basically what we want why we want to renew our IP each time we make it request is so that tour the tour servers don't get banned from websites that we're using either because this is a public service essentially that they're using people volunteer their servers when they're using this information so we don't want to abuse the system and get a bunch of Tora servers banned from web sites you know so yeah anyway so we're gonna run this real quickly and it should work and should give us the IP of what our current setup is with the connection to tor if we run it again it'll be the same it should be the same IP again because we didn't reset it see we didn't reset it there so it gave us the same IP we want to be able to change what that Ikey is each time we make a request to the server and that's what these lines here have to do for us right here we do alt 3 again or Alta for my bad I think this one was a commented out here so we're gonna do that following prints your normal IP address so yeah I wanted to comment that out that is my bad actually so we're gonna alt 3 there and that comments things out quickly for us now if we imports them signal from stem we will import control from stem dock control controller from send out control then we signal tour for a new connection this is a basic function that essentially creates a new IP when we want to make a new request to wherever we're going if we didn't want to you know maybe we want to make 10 requests and then reset our IP so that way it's not seen as like abusing systems or whatnot or we're going to places that we shouldn't be going so we're gonna reset our IP so it's difficult more difficult for nefarious individuals to track us now we renew the connection we set a width as setup here I forget I don't forget what this is called again but anyways we use the control port remember the control port we set in the torque file to be uncommented in the torque file this is where that comes into play here so we set the front port not port 1951 as can and we do controller to authenticate our password because we're gonna start using this control port and then we're gonna say control signal signal new and ym that's basically gonna tell the Tor network that we want a new connection we want to reset the connection to the Tor network essentially and when that runs we run renew connection first we've got to run the function in order to change the IP we create a new session object and then what we want to do is we want to print the new IP that we have so we're gonna run this and you'll see that the first IP that we get is our original IP and then once it gets to this coat down here it resets RFP so we see the first one and we see the second one so as you can see these are two completely different IP addresses that we've gone through to to this website right here which is HTTP pin org slash IP and that gets the you know that gets the your IP address from the website's perspective and yeah so if you liked the video leave like one see more subscribe if one helps put the channel click the my single critic update if you want to see a a more detailed version of this you can click on the blog link below and get all the code that's in the description below and I'll see you all next time bye bye
Info
Channel: computerScienceAndFangs
Views: 12,320
Rating: 4.7833934 out of 5
Keywords: tor and python, python requests, anonymize ip python, hide ip python, python, tor, python and tor, python 3, py3, py3 and tor
Id: wJfa0qEzpJc
Channel Id: undefined
Length: 19min 2sec (1142 seconds)
Published: Wed Apr 04 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.