|
@@ -1,38 +1,41 @@
|
|
|
|
+from http.server \
|
|
|
|
+ import HTTPServer, BaseHTTPRequestHandler
|
|
|
|
+import requests
|
|
|
|
+import datetime
|
|
|
|
|
|
-from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-class HttpGethandler(BaseHTTPRequestHandler):
|
|
|
|
|
|
+class HttpGetHandler(BaseHTTPRequestHandler):
|
|
def do_GET(self):
|
|
def do_GET(self):
|
|
try:
|
|
try:
|
|
- if self.path.endswith("/OK"):
|
|
|
|
|
|
+ if self.path.endswith("/Status"):
|
|
self.send_response(200)
|
|
self.send_response(200)
|
|
-
|
|
|
|
- self.send_header("Content-type", "text/html")
|
|
|
|
|
|
+ self.send_header("Content-type","text/html")
|
|
self.end_headers()
|
|
self.end_headers()
|
|
-
|
|
|
|
- http_text = """<html><head><meta charset='utf-8'
|
|
|
|
- <title>Есть</title></head>
|
|
|
|
- <body>HTTP-статус 200</body></html>"""
|
|
|
|
-
|
|
|
|
|
|
+ get = requests.get('https://api.ipify.org/')
|
|
|
|
+ http_text = f"<html><head><meta charset = 'utf-8'>" \
|
|
|
|
+ f"<title>Простой HTTP-сервер.</title></head>" \
|
|
|
|
+ f"<body>Ваш адресс {get.text}.<br>" \
|
|
|
|
+ f"<body> Моллаев Омар Рашидович 701(3) группа <br>" \
|
|
|
|
+ f"Время на сервере {str(datetime.datetime.now())}" \
|
|
|
|
+ f"</body></html>"
|
|
self.wfile.write(http_text.encode())
|
|
self.wfile.write(http_text.encode())
|
|
|
|
|
|
|
|
+
|
|
if self.path.endswith("/info"):
|
|
if self.path.endswith("/info"):
|
|
self.send_response(200)
|
|
self.send_response(200)
|
|
-
|
|
|
|
self.send_header("Content-type", "text/html")
|
|
self.send_header("Content-type", "text/html")
|
|
self.end_headers()
|
|
self.end_headers()
|
|
|
|
|
|
- http_text = """<html><head><meta charset='utf-8'
|
|
|
|
- <title>Моллаев Омар Рашидович 701(3)</title></head></html>"""
|
|
|
|
|
|
+ html = """ <html><head><meta charset = 'utf-8'>
|
|
|
|
+ <title>Простой HTTP-сервер.</title></head>
|
|
|
|
+ <body>Моллаев Омар Рашидович,студент 701(3) группы.</body></html> """
|
|
|
|
|
|
- self.wfile.write(http_text.encode())
|
|
|
|
|
|
+ self.wfile.write(html.encode())
|
|
|
|
|
|
except IOError:
|
|
except IOError:
|
|
- self.send_error(400, "No found {self.path}")
|
|
|
|
|
|
+ self.send_error(400,"File not found{self.path}")
|
|
|
|
|
|
|
|
|
|
-def main(server_class=HTTPServer, handler_class=HttpGethandler):
|
|
|
|
|
|
+def main(server_class=HTTPServer, handler_class=HttpGetHandler):
|
|
server_address = ('localhost', 8000)
|
|
server_address = ('localhost', 8000)
|
|
httpd = server_class(server_address, handler_class)
|
|
httpd = server_class(server_address, handler_class)
|
|
try:
|
|
try:
|
|
@@ -41,8 +44,9 @@ def main(server_class=HTTPServer, handler_class=HttpGethandler):
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
except KeyboardInterrupt:
|
|
httpd.server_close()
|
|
httpd.server_close()
|
|
- print("Красный Свет")
|
|
|
|
|
|
+ print("Красный свет")
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
- main()
|
|
|
|
|
|
+ main()
|
|
|
|
+
|