Question

Currently I am in need of being able to tell the difference between a private address and a web reachable one.

I need to be able to test for the following:

You are given a list of ipv6 on an interface and need to know which addresses are web reachable. It is possible for none of these addresses to be non private. If the address is changed, it would be best to be able to track which one (I can figure that out after I have a private address test method).

This is written in javascript on node.js

Was it helpful?

Solution

What you're looking for is the IPv6 scope: "web reachable" are addresses in the global scope. The scopes are described here:

http://en.wikipedia.org/wiki/IPv6_address#IPv6_address_scopes

You could parse the address yourself -- OR you could save yourself some time and use the ipv6 module (npm install ipv6 --save):

var v6 = require('ipv6').v6;

var addr = new v6.Address('2001:db8:85a3:8d3:1319:8a2e:370:7348');

if(addr.getScope()==='Global'){
    console.log('valid global ipv6 address');
}

Disclaimer: I don't really know that much about IPv6...but I'm figuring it out. I found this discussion of the different scopes useful, by the way:

Link-local and global IPs on IPv6 interfaces

OTHER TIPS

I'm working with the following assumptions:

  • you're using appropriate standards to define private vs. web-reachable
  • for our purposes web-reachable means not private
  • in particular, we're only interested in the format of the address, not whether a device will actually respond at that address

... with those assumptions, it should be fairly easy. According to this page (which links here), you just have to test that the address starts with fd1, perhaps with the regular expression /^fd1/, to confirm that it is a private address.

Likewise, according to this page, you can test for 0:0:0:0:0:0:0:1 or ::1 for the loopback address.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top