Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ifaces[ifname].forEach(function (iface) {
if (iface.internal !== false) {
// skip over internal (i.e. 127.0.0.1)
return;
}
//set IPv4 address
if ('IPv4' === iface.family) {
var address4 = new ipAddress.Address4(iface.address);
if (address4.isValid()) {
global.AddressIpv4 = iface.address;
global.hasAddressIpv4 = true;
}
}
//set IPv6 address
if (('IPv6' === iface.family)) {
var address6 = new ipAddress.Address6(iface.address);
//Only globally scoped IPv6 addresses can be reached externally
if(address6.isValid() && address6.getScope() === 'Global'){
global.AddressIpv6 = iface.address;
global.hasAddressIpv6 = true;
}
}
++alias;
});
});
b.writeUInt32BE(eip[i], offset)
offset += 4
}
b.writeUInt32BE(locId >>> 0, 32)
lat = Math.round(parseFloat(fields[7]) * 10000)
lon = Math.round(parseFloat(fields[8]) * 10000)
area = parseInt(fields[9], 10)
b.writeInt32BE(lat, 36)
b.writeInt32BE(lon, 40)
b.writeInt32BE(area, 44)
} else {
// IPv4
bsz = 24
rngip = new Address4(fields[0])
sip = parseInt(rngip.startAddress().bigInteger(), 10)
eip = parseInt(rngip.endAddress().bigInteger(), 10)
locId = parseInt(fields[1], 10)
locId = cityLookup[locId]
b = Buffer.alloc(bsz)
b.fill(0)
b.writeUInt32BE(sip >>> 0, 0)
b.writeUInt32BE(eip >>> 0, 4)
b.writeUInt32BE(locId >>> 0, 8)
lat = Math.round(parseFloat(fields[7]) * 10000)
lon = Math.round(parseFloat(fields[8]) * 10000)
area = parseInt(fields[9], 10)
b.writeInt32BE(lat, 12)
b.writeInt32BE(lon, 16)
b.writeInt32BE(area, 20)
b.writeUInt32BE(eip[i], offset);
offset += 4;
}
b.writeUInt32BE(locId>>>0, 32);
lat = Math.round(parseFloat(fields[7]) * 10000);
lon = Math.round(parseFloat(fields[8]) * 10000);
area = parseInt(fields[9], 10);
b.writeInt32BE(lat,36);
b.writeInt32BE(lon,40);
b.writeInt32BE(area,44);
} else {
// IPv4
bsz = 24;
rngip = new Address4(fields[0]);
sip = parseInt(rngip.startAddress().bigInteger(),10);
eip = parseInt(rngip.endAddress().bigInteger(),10);
locId = parseInt(fields[1], 10);
locId = cityLookup[locId];
b = Buffer.alloc(bsz);
b.fill(0);
b.writeUInt32BE(sip>>>0, 0);
b.writeUInt32BE(eip>>>0, 4);
b.writeUInt32BE(locId>>>0, 8);
lat = Math.round(parseFloat(fields[7]) * 10000);
lon = Math.round(parseFloat(fields[8]) * 10000);
area = parseInt(fields[9], 10);
b.writeInt32BE(lat,12);
b.writeInt32BE(lon,16);
b.writeInt32BE(area,20);
sip = utils.aton6(rngip.startAddress().correctForm())
eip = utils.aton6(rngip.endAddress().correctForm())
b = Buffer.alloc(bsz)
for (i = 0; i < sip.length; i++) {
b.writeUInt32BE(sip[i], i * 4)
}
for (i = 0; i < eip.length; i++) {
b.writeUInt32BE(eip[i], 16 + i * 4)
}
} else {
// IPv4
bsz = 10
rngip = new Address4(fields[0])
sip = parseInt(rngip.startAddress().bigInteger(), 10)
eip = parseInt(rngip.endAddress().bigInteger(), 10)
b = Buffer.alloc(bsz)
b.fill(0)
b.writeUInt32BE(sip, 0)
b.writeUInt32BE(eip, 4)
}
b.write(cc, bsz - 2)
fs.writeSync(datFile, b, 0, bsz, null)
if (Date.now() - tstart > 5000) {
tstart = Date.now()
process.stdout.write('\nStill working (' + lines + ') ...')
}
const _ip6To4 = ip6 => new ipAddress.Address6(ip6).to4().address;
// const _ip4To6 = ip4 => '::ffff:' + ip4;
var locId
var b
var bsz
var lat
var lon
var area
var i
lines++
if (fields[0].match(/:/)) {
// IPv6
var offset = 0
bsz = 48
rngip = new Address6(fields[0])
sip = utils.aton6(rngip.startAddress().correctForm())
eip = utils.aton6(rngip.endAddress().correctForm())
locId = parseInt(fields[1], 10)
locId = cityLookup[locId]
b = Buffer.alloc(bsz)
b.fill(0)
for (i = 0; i < sip.length; i++) {
b.writeUInt32BE(sip[i], offset)
offset += 4
}
for (i = 0; i < eip.length; i++) {
b.writeUInt32BE(eip[i], offset)
offset += 4
.map(function(line) {
var data = line.split(',');
if (!data || data.length < 2) {
console.error('[ERROR]', 'Bad line:', line);
return;
}
var geonameId = parseInt(data[1].replace(/"/g, ''));
var ipv4Cidr = data[0].replace(/"/g, '');
var ipv4Address = new Address4(ipv4Cidr);
var ipv4StartAddress = ipv4Address.startAddress().correctForm();
var ipv4EndAddress = ipv4Address.endAddress().correctForm();
var block = {
geoname_id: geonameId,
ipv4_start_int: utils.ipv4ToInt(ipv4StartAddress)
};
if (ipv4StartAddress !== ipv4EndAddress) {
block.ipv4_end_int = utils.ipv4ToInt(ipv4EndAddress);
}
countryBlocksIpv4.push(block);
})
.on('pipe', function() {
window.AWS_RANGE_6 = j.ipv6_prefixes.map(p => {
const addr = new IpAddr.Address6(p.ipv6_prefix)
return {
addr,
region: p.region,
service: p.service
}
}).reverse()
console.log('...done IP range fetch')
, idStr;
idBuf.fill(0);
idBuf.writeUInt16BE(socket.remotePort, 16);
if (net.isIPv4(socket.remoteAddress)) {
idBuf.writeUInt8(4, 18);
idBuf = socket.remoteAddress.split('.')
.reduce(
function (o, v, i) {
o.writeUInt8(v, i);
return o;
}
, idBuf
);
} else {
idBuf.writeUInt8(6, 18);
idBuf = (new ip.v6.Address(socket.remoteAddress)).parsedAddress
.reduce(
function (o, v, i) {
o.writeUInt16BE(v, i * 2);
return o;
}
, idBuf
);
}
idStr = idBuf.toString('hex');
this.client_sockets[idStr] = socket;
this.connection.sendUTF('NEW ' + idStr);
socket.on('close', function () {
self.connection.sendUTF('END ' + idStr);
delete self.client_sockets[idStr];
});
public static getAddress6(host: string): Address6 | null | undefined {
const parts = host.split('.');
return parts.length === 4 ? Address6.fromAddress4(host) : new Address6(host);
}