yps.py 828 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/python3
  2. import socket
  3. from http.server import HTTPServer, SimpleHTTPRequestHandler
  4. import argparse
  5. class MyHandler(SimpleHTTPRequestHandler):
  6. def do_GET(self):
  7. if self.path == '/ip':
  8. self.send_response(200)
  9. self.send_header('Content-type', 'text/html')
  10. self.end_headers()
  11. self.wfile.write('ip adresiniz %s' % self.client_address[0])
  12. return
  13. else:
  14. return SimpleHTTPRequestHandler.do_GET(self)
  15. class HTTPServerV6(HTTPServer):
  16. address_family = socket.AF_INET6
  17. def main():
  18. parser = argparse.ArgumentParser(description='yerel pratik sunucu')
  19. parser.add_argument('-p', '--port', help='calisma portu', type=int, default=9000)
  20. args = parser.parse_args()
  21. server = HTTPServerV6(('::', args.port), MyHandler)
  22. server.serve_forever()
  23. if __name__ == '__main__':
  24. main()