Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. function getip(req) {
  2. var headerip = req.headers ? getheaderip(req) : 'unknown'
  3. if (headerip.length > 15) {headerip = headerip.match(/\d+\.\d+\.\d+\.\d/g)[0]}
  4. return headerip
  5. function getheaderip(req) {
  6. return req.headers['x-forwarded-for']
  7. ? req.headers['x-forwarded-for']
  8. : (req.connection && req.connection.remoteAddress)
  9. ? req.connection.remoteAddress
  10. : (req.connection.socket && req.connection.socket.remoteAddress)
  11. ? req.connection.socket.remoteAddress
  12. : (req.socket && req.socket.remoteAddress)
  13. ? req.socket.remoteAddress
  14. : '0.0.0.0';
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement