Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the domain name or ip of the PC accessing my API method? [duplicate]

I have an API method deploy on my local server,

@app.post("/test/api")
async def method():
     if incoming.request.url or domain == "this":
         do some operation
     else:
         skip it
     .....
     return something

Now, Few people are using my API method, but is there any way I could track who is calling my api method and do specific extra operations to the once I specified who is calling my api.

How can I track the incoming domain name or ip or url of the people who are using my api method?

Note: Need a basic example on how to acheive it if you familiar with it

Is it something possible?

like image 836
user_12 Avatar asked Dec 14 '25 21:12

user_12


1 Answers

If you were using flask it could happen simply by getting remote_addr as below:

from flask import FLASK, request
@app.route('/test/api', methods=['POST']):
def method():
    visitor_ip = request.remote_addr

In fastapi it should happen like this: request.client.host

any way you can work with headers in your code and get many details of your client

like image 104
Maziar Shahsavan Avatar answered Dec 16 '25 11:12

Maziar Shahsavan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!