1

I am setting python local server using python -m SimpleHTTPServer, I made that server publicly available using ngrock and have some public IP address like http://2ee94---.ngrok.io. Now I am making the request to the public IP address. I want to get IP address from request. But I am getting the only status in the terminal. How to get details (IP address of client) of the request.

HTTP Requests                                                                   
-------------                                                                   

GET  /                         200 OK                                           
GET  /                         200 OK  
6
  • which details you want ? Commented Sep 17, 2019 at 12:00
  • IP address of the client, who is making a request to the server. Commented Sep 17, 2019 at 12:00
  • 3
    SimpleHTTPServer is, well, simple. Probably you want a more full-featured server…!? Commented Sep 17, 2019 at 12:01
  • 1
    Possible duplicate: stackoverflow.com/questions/37055005/… Commented Sep 17, 2019 at 12:06
  • 2
    Possible duplicate of How to get client IP from SimpleHTTPServer Commented Sep 17, 2019 at 12:23

1 Answer 1

0

I got it done after setting up my own handler class,

import SimpleHTTPServer
import SocketServer


class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def handle_one_request(self):
        print(self.client_address[0])
        return SimpleHTTPServer.SimpleHTTPRequestHandler.handle_one_request(self)

httpd = SocketServer.TCPServer(("", 8080), MyHandler)

while True:
    httpd.handle_request()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.