milis/bin/yps.py

34 lines
1.0 KiB
Python
Raw Normal View History

2017-02-09 22:20:55 +01:00
#!/usr/bin/python3
import socket
from http.server import HTTPServer, SimpleHTTPRequestHandler
import argparse
2017-05-25 23:12:59 +02:00
import os
2017-02-09 22:20:55 +01:00
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('ip adresiniz %s' % self.client_address[0])
return
else:
return SimpleHTTPRequestHandler.do_GET(self)
class HTTPServerV6(HTTPServer):
address_family = socket.AF_INET6
def main():
2017-05-25 23:12:59 +02:00
suankiyer=os.getcwd()
2017-02-09 22:20:55 +01:00
parser = argparse.ArgumentParser(description='yerel pratik sunucu')
parser.add_argument('-p', '--port', help='calisma portu', type=int, default=9000)
2017-05-25 23:12:59 +02:00
parser.add_argument('-d', '--directory', help='calisma dizini', type=str,default=suankiyer)
2017-02-09 22:20:55 +01:00
args = parser.parse_args()
2017-05-25 23:12:59 +02:00
print ("çalışma dizini: ",args.directory)
os.chdir(args.directory)
2017-02-09 22:20:55 +01:00
server = HTTPServerV6(('::', args.port), MyHandler)
server.serve_forever()
if __name__ == '__main__':
main()