request.connection.remoteAddress Now Prefixed in ::ffff in node.js

后端 未结 2 570
执笔经年
执笔经年 2020-12-23 11:31

I recently changed my router over to one provided by Google for Google Fiber (yay!) and now I am noticing a change in what I am seeing when I inspect request.connection.remo

2条回答
  •  抹茶落季
    2020-12-23 12:12

    re: #4, a library like ipaddr.js works well, e.g.:

    var ipString = request.connection.remoteAddress;
    if (ipaddr.IPv4.isValid(ipString)) {
      // ipString is IPv4
    } else if (ipaddr.IPv6.isValid(ipString)) {
      var ip = ipaddr.IPv6.parse(ipString);
      if (ip.isIPv4MappedAddress()) {
        // ip.toIPv4Address().toString() is IPv4
      } else {
        // ipString is IPv6
      }
    } else {
      // ipString is invalid
    }
    

提交回复
热议问题