Skip to content

Instantly share code, notes, and snippets.

@timhughes
Created October 11, 2019 14:30
Show Gist options
  • Save timhughes/4f82cc72e31f878935ea86294854cee7 to your computer and use it in GitHub Desktop.
Save timhughes/4f82cc72e31f878935ea86294854cee7 to your computer and use it in GitHub Desktop.
ipv6server.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 Tim Hughes <[email protected]>
#
# Distributed under terms of the MIT license.
"""
"""
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment