问题
I am writing a bot in node.js. May I know how can I insert code to console.log the IP address of message sender please? I need the IP address to perform some auto-log in.
Many Thanks!!
回答1:
You can get ip address from request object by
request.connection.remoteAddress
回答2:
To get the Ip address of your User
var app = require('express')();
app.get("/ip", (req, res) => {
console.log(req.ip) // "::ffff:127.0.0.1" ::ffff: is a subnet prefix for IPv4 (32 bit)
let ip = req.ip.split(':');
console.log(ip[3]);
res.json(ip[3]); // ==> 127.0.0.1 You can Get Your Ip address only
});
app.listen(3003);
回答3:
Just want to let you know that the thing that worked for me was this:
server.post('/api/messages', [
function(req,res,next){
console.log(req.connection.remoteAddress);
next();
},
connector.listen()
]);
Source: https://github.com/Microsoft/BotBuilder/issues/3316
来源:https://stackoverflow.com/questions/42452028/how-to-get-users-ip-address-in-a-bot-with-node-js