yps.py 1.0 KB

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