Quality fixes
This commit is contained in:
1 parent
590fd37831
commit
f6774898b5
1 file changed
+12
-8
@@ -2,12 +2,12 @@ const os = require('node:os');
|
||||
const axios = require('./axios.js');
|
||||
const isLocalIP = require('./isLocalIP.js');
|
||||
|
||||
let ipAddressList = [];
|
||||
const ipAddressList = new Set();
|
||||
|
||||
const fetchIPv4Address = async () => {
|
||||
try {
|
||||
const { data } = await axios.get('https://api.sefinek.net/api/v2/ip');
|
||||
if (data?.success && data?.message) ipAddressList.push(data.message);
|
||||
if (data?.success && data?.message) ipAddressList.add(data.message);
|
||||
} catch (err) {
|
||||
console.warn('Error fetching IPv4 address:', err.message);
|
||||
}
|
||||
@@ -16,16 +16,18 @@ const fetchIPv4Address = async () => {
|
||||
const fetchIPv6Address = () => {
|
||||
const networkInterfaces = os.networkInterfaces();
|
||||
|
||||
for (const interfaces of Object.values(networkInterfaces)) {
|
||||
for (const details of interfaces) {
|
||||
Object.values(networkInterfaces).forEach(interfaces => {
|
||||
interfaces.forEach(details => {
|
||||
const ip = details.address;
|
||||
if (!details.internal && ip && !isLocalIP(ip)) ipAddressList.push(ip);
|
||||
}
|
||||
if (!details.internal && ip && !isLocalIP(ip)) {
|
||||
ipAddressList.add(ip);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const fetchIPAddress = async () => {
|
||||
ipAddressList = [];
|
||||
ipAddressList.clear();
|
||||
await fetchIPv4Address();
|
||||
fetchIPv6Address();
|
||||
};
|
||||
@@ -33,6 +35,8 @@ const fetchIPAddress = async () => {
|
||||
(async () => {
|
||||
await fetchIPAddress();
|
||||
setInterval(fetchIPAddress, 25 * 1000);
|
||||
|
||||
// console.debug(ipAddressList);
|
||||
})();
|
||||
|
||||
module.exports = () => [...ipAddressList];
|
||||
module.exports = () => Array.from(ipAddressList);
|
||||
Reference in new issue
Block a user