🛠 Utilities for getting / processing dats

This commit is contained in:
Alicia Sykes 2022-07-08 21:48:38 +01:00
parent 68864366af
commit fbfe1a0328
2 changed files with 89 additions and 0 deletions

6
src/utils/get-keys.ts Normal file
View File

@ -0,0 +1,6 @@
const keys = {
shodan: process.env.SHODAN_API_KEY,
};
export default keys;

View File

@ -0,0 +1,83 @@
export interface ServerLocation {
city: string,
region: string,
country: string,
postCode: string,
regionCode: string,
countryCode: string,
coords: {
latitude: number,
longitude: number,
},
isp: string,
timezone: string,
languages: string,
currency: string,
currencyCode: string,
countryDomain: string,
countryAreaSize: number,
countryPopulation: number,
};
export const getLocation = (response: any): ServerLocation => {
return {
city: response.city,
region: response.region,
country: response.country_name,
postCode: response.postal,
regionCode: response.region_code,
countryCode: response.country_code,
coords: {
latitude: response.latitude,
longitude: response.longitude,
},
isp: response.org,
timezone: response.timezone,
languages: response.languages,
currencyCode: response.currency,
currency: response.currency_name,
countryDomain: response.country_tld,
countryAreaSize: response.country_area,
countryPopulation: response.country_population,
};
};
export interface ServerInfo {
org: string,
asn: string,
isp: string,
os?: string,
};
export const getServerInfo = (response: any): ServerInfo => {
return {
org: response.org,
asn: response.asn,
isp: response.isp,
os: response.os,
};
};
export interface HostNames {
domains: string[],
hostnames: string[],
};
export const getHostNames = (response: any): HostNames => {
const { hostnames, domains } = response;
const results: HostNames = {
domains: [],
hostnames: [],
};
if (!hostnames || !domains) return results;
hostnames.forEach((host: string) => {
if (domains.includes(host)) {
results.domains.push(host);
} else {
results.hostnames.push(host);
}
});
return results;
};