2023-08-01 10:49:59 +00:00
|
|
|
import * as plugins from './plugins.js';
|
|
|
|
import * as paths from './paths.js';
|
|
|
|
import * as helpers from './helpers.js';
|
|
|
|
|
|
|
|
export interface IFeodoTrackerData {
|
2023-08-01 11:01:48 +00:00
|
|
|
ip_address: string;
|
|
|
|
port: number;
|
|
|
|
status: string;
|
|
|
|
hostname: string | null;
|
|
|
|
as_number: number;
|
|
|
|
as_name: string;
|
|
|
|
country: string;
|
|
|
|
first_seen: string;
|
|
|
|
last_online: string;
|
|
|
|
malware: string;
|
2023-08-01 10:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class FeodoTracker {
|
2023-08-01 11:01:48 +00:00
|
|
|
private static readonly FEODO_TRACKER_API_URL: string = 'https://feodotracker.abuse.ch/downloads/ipblocklist.json';
|
2023-08-01 10:49:59 +00:00
|
|
|
|
|
|
|
public async getData(): Promise<IFeodoTrackerData[]> {
|
|
|
|
const response = await plugins.nodeFetch(FeodoTracker.FEODO_TRACKER_API_URL, {
|
|
|
|
...(helpers.findProxy() ? {
|
|
|
|
agent: helpers.getAgent(),
|
|
|
|
} : {})
|
|
|
|
});
|
2023-08-01 11:01:48 +00:00
|
|
|
|
2023-08-01 10:49:59 +00:00
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
}
|
|
|
|
|
2023-08-01 11:02:04 +00:00
|
|
|
const data: IFeodoTrackerData[] = await response.json() as IFeodoTrackerData[];
|
2023-08-01 11:01:48 +00:00
|
|
|
|
|
|
|
// Ensure the data is an array and has the expected structure
|
|
|
|
if (!Array.isArray(data) || !data.every(item =>
|
|
|
|
typeof item.ip_address === 'string' &&
|
|
|
|
typeof item.port === 'number' &&
|
|
|
|
(typeof item.hostname === 'string' || item.hostname === null) &&
|
|
|
|
typeof item.as_number === 'number' &&
|
|
|
|
typeof item.as_name === 'string' &&
|
|
|
|
typeof item.country === 'string' &&
|
|
|
|
typeof item.first_seen === 'string' &&
|
|
|
|
typeof item.last_online === 'string' &&
|
|
|
|
typeof item.malware === 'string'
|
|
|
|
)) {
|
|
|
|
throw new Error(`Invalid data structure!`);
|
|
|
|
}
|
2023-08-01 10:49:59 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
2023-08-01 11:01:48 +00:00
|
|
|
|