Aug 12, 2019

How to use python as a http server

Hello guys, Today I'm hear with another quick tutorial. in this one I'll explain you how we can use python as a http web server. Yes we have apache2 and nginx. But for some quick and short works this tool is so handy. We can build a simple server wiyhing a single line of python code. Let's see how. First i'm going to show you how we can use it in python 2.x version. Hear we have a module called SimpleHTTPServer. The syntax for use it is python -m SimpleHTTPServer [port] The default port is 8000. So if you don't specify a port it will be used. Let's serve on port 4444.
python -m SimpleHTTPServer 4444
Now we can browse it through our browser. If you visiting it in same host you have to go If you have added an index.html file it will be displayed. If not you can see the directory listing of current folder.   python http server Awesome ! . it's working fine.  Do you want to see above html source too? why can't. :-)
<!DOCTYPE html><html><head><style type="text/css">.heading{text-align: center;color: lime;font-size: 72px;}.sub-heading{text-align: center;color: white;font-size: 40px;}.hl{text-align: center;font-size: 96px;color: white;}.hl-up{color: red;text-align: center;font-size: 96px;}a{text-decoration: none;}body{background: black;}</style><title>Blog of Thilan</title></head><body><h1 class="heading"> Welcome to </h1><a href=""><h1 class="hl"><span class="hl-up">H</span>acks<span class="hl-up">L</span>and</h1></a></body></html>
Just for fun. :-p When sombody visit the server , HTTP requests will be logged on the terminal. Also this server will serve until you close the shell.  
[email protected]:~$ python -m SimpleHTTPServer 4444
Serving HTTP on port 4444 ... - - [26/Jun/2019 18:05:15] "GET / HTTP/1.1" 200 - - - [26/Jun/2019 18:06:37] code 404, message File not found - - [26/Jun/2019 18:06:37] "GET /any.html HTTP/1.1" 404 -
Now we can use it on python 3.x versions too. Hear we have to use http module instead of simpleHttpServer. The syntax is same.
python3 -m http.server 8000
So guys it's all for this tutorial. Yes it was a short and quick one. But we can use this trick in many times. In futurre tutorials I'll show you how we can use this in ctf , and web applicatio pentesting.Thank for reading. :-)
Aug 12
Lists & Dictionaries | Python programming

A list is a way to store data. In languages like C, php we saw they use a special type of variable....

Aug 12
Outputs in C

In C there are number of ways to getting output to the screen.You can use them according to your....

Aug 12
Error Handling | Python Programming

Errors are absolutely normal when programming. You may get hundred of errors while learning. Not....

Replying to 's comment Cancel reply
Thilan Danushka Dissanayaka

Thilan Dissanayaka

Hi, I'm Thilan from Srilanka. An undergraduate Engineering student of University of Ruhuna. I love to explorer things about CS, Hacking, Reverse engineering etc.