-
Notifications
You must be signed in to change notification settings - Fork 0
/
whereamid
executable file
·45 lines (36 loc) · 1.26 KB
/
whereamid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, HTTPServer
import setproctitle
import os
import syslog
class Logger:
def log(message):
syslog.syslog(syslog.LOG_INFO | syslog.LOG_DAEMON, message)
def err(message):
syslog.syslog(syslog.LOG_ERR | syslog.LOG_DAEMON, message)
class HTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
Logger.log("Request from %s: '%s'" % (self.client_address[0], self.requestline));
if self.path == '/':
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
message = self.client_address[0] + "\n"
self.wfile.write(bytes(message, "utf8"))
else:
self.send_error(404, "Not Found")
return
def run(port = 80):
Logger.log("Listening on port %d" % port);
server_address = ('', port)
httpd = HTTPServer(server_address, HTTPServer_RequestHandler)
httpd.serve_forever()
def log_message(self, format, *args):
return
def main():
title = os.path.basename(__file__)
setproctitle.setproctitle(title)
syslog.openlog(title);
HTTPServer_RequestHandler.run(8484)
if __name__ == "__main__":
main()