Skip to content

Instantly share code, notes, and snippets.

@orleika
Created January 25, 2015 13:47
Show Gist options
  • Save orleika/45ae49db4066f577fc7b to your computer and use it in GitHub Desktop.
Save orleika/45ae49db4066f577fc7b to your computer and use it in GitHub Desktop.
Node.jsでの接続元IPアドレス取得
var getIP = function (req) {
if (req.headers['x-forwarded-for']) {
return req.headers['x-forwarded-for'];
}
if (req.connection && req.connection.remoteAddress) {
return req.connection.remoteAddress;
}
if (req.connection.socket && req.connection.socket.remoteAddress) {
return req.connection.socket.remoteAddress;
}
if (req.socket && req.socket.remoteAddress) {
return req.socket.remoteAddress;
}
return '0.0.0.0';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment