As IPv4 is already exhausted, so many ISP is switching to a mixture of private IPv4 and public IPv6 network. So, it opened a scope for many to experiment with IPv6, share files or simply server a web page over IPv6.
But just for serving few static page over IPv6, most of you won't like to setup heavy weight servers like NGINX, Apache for that.
Previously I wrote about 5 simple web server, but most of them has no IPv6 support.
So, here's a simple python script as a basic IPv6 capable web server, based on python SimpleHTTPServer module.
The IPv6 web server script
Here's the script, written with python2.7.x series.
import socket from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler class MyHandler(SimpleHTTPRequestHandler): def do_GET(self): if self.path == '/ip': self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write('Your IP address is %s' % self.client_address) return else: return SimpleHTTPRequestHandler.do_GET(self) class HTTPServerV6(HTTPServer): address_family = socket.AF_INET6 def main(): server = HTTPServerV6(('::', 8080), MyHandler) server.serve_forever() if __name__ == '__main__': main()
That's it, save the the script as whatever you want, I saved it as
You can change the port number to your desired port in the script.
Running and testing the web server script
You can run the script with the python command,
By default it binds all the the interfaces with IPv6 address to the port 8080, you can check with
netstat command or a web browser.
If there's a index.html file, it will be served as default page, unless there will be a directory listing of the pwd.
So, first find out your IPv6 address and construct the IPv6 URL like this,
[your_IPv5_address]:8080, a more prominent example could be like below.
Credit and conclusion
A big thanks to the script author, Alexander Korobov, link to the original script here.
So, that's all about how you can create a simple IPv6 web server with python, I hope that's interesting enough.
If you have any question or suggestion, please leave comments.