How to know the IP Address of MQTT client on receive of message at server side. I am using a mosquitto broker.
2 Answers
TLDR; You don't.
The point of a Pub/Sub protocol like MQTT is to totally decouple the publisher and the subscriber. A given message is passed to the broker by the publisher, at this point it hands off all responsibility for that message to the broker, which sends it on to the clients subscribed to the topic it was published on.
There is no information held in the message (at the MQTT protocol level) about where it comes from, only the topic and if it's a retained message.
If you need to know more information about the publisher then you will need to encode that information into the message payload yourself.
I also covered most of this in the answer to your previous question.

- 54,545
- 11
- 67
- 105
To get the IP address of a client in MQTT, you'd have to put it yourself into the body of the message.
If you are using mosquito with nodejs, you could get the client IP via node network interfaces or other node modules like here:
How can I get the local IP address in Node.js?