Created
March 11, 2020 09:28
-
-
Save kylemocode/7251bec91a53672fa8da3cf63dc675ca to your computer and use it in GitHub Desktop.
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
import { Request } from 'express'; | |
export const getClientIp = function (req: Request) { | |
const ipInfo: any = req.socket.address(); | |
let ipAddress = ipInfo.address; | |
if (!ipAddress) { | |
return ''; | |
} | |
// convert from "::ffff:192.0.0.1" to "192.0.0.1" | |
if (ipAddress.substr(0, 7) == "::ffff:") { | |
ipAddress = ipAddress.substr(7) | |
} | |
return ipAddress; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment