コード例 #1
0
ファイル: checkIpInList.ts プロジェクト: RiseVision/rise-node
function getAddressClass(addr: string): Address4|Address6 {
  const address4 = new Address4(addr);
  if (address4.isValid()) {
    return address4;
  }
  const address6 = new Address6(addr);
  if (address6.isValid()) {
    return address6;
  }
  throw new Error(`Address ${addr} is neither v4 or v6`);
}
コード例 #2
0
 constructor(addr: string) {
   var addr4 = new Address4(addr);
   if (!addr4.isValid()) {
     var addr6 = new Address6(addr);
     if (!addr6.isValid()) {
       throw new Error('Invalid ip address');
     } else {
       this.addr6 = addr6;
     }
   } else {
     this.addr4 = addr4;
   }
 }
コード例 #3
0
ファイル: integration.test.ts プロジェクト: runk/node-maxmind
 const tester = (geoIp: Reader<Response>, data: any) => {
   for (const subnet in data.hash) {
     const ip = new ipaddr.Address6(subnet);
     // TODO: check random address from the subnet?
     // see http://ip-address.js.org/#address4/biginteger
     // see https://github.com/andyperlitch/jsbn
     assert.deepEqual(
       geoIp.get(ip.startAddress().address),
       data.hash[subnet],
       subnet
     );
     assert.deepEqual(
       geoIp.get(ip.endAddress().address),
       data.hash[subnet],
       subnet
     );
   }
 };