Created
January 25, 2015 13:47
-
-
Save orleika/45ae49db4066f577fc7b to your computer and use it in GitHub Desktop.
Node.jsでの接続元IPアドレス取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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