Skip to content

Instantly share code, notes, and snippets.

@vova
Forked from akorobov/ipv6-httpd.py
Created February 15, 2025 21:10
Show Gist options
  • Select an option

  • Save vova/2376f943961c0cab125d609c0b364ba4 to your computer and use it in GitHub Desktop.

Select an option

Save vova/2376f943961c0cab125d609c0b364ba4 to your computer and use it in GitHub Desktop.
quick ipv6 http server using python's SimpleHttpServer
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[0])
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()
@vova
Copy link
Author

vova commented Feb 15, 2025

for python 3 just:
python3 -m http.server -b 2603:4000:3bd0::786:bbad:1e5d 8080

or even
python3 -m http.server --bind ::

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment