From fbfe1a0328edd316bdc4f950e6f5d4dfa061d690 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 8 Jul 2022 21:48:38 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20Utilities=20for=20getting=20/=20?= =?UTF-8?q?processing=20dats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/get-keys.ts | 6 +++ src/utils/result-processor.ts | 83 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 src/utils/get-keys.ts create mode 100644 src/utils/result-processor.ts diff --git a/src/utils/get-keys.ts b/src/utils/get-keys.ts new file mode 100644 index 0000000..bc4f85e --- /dev/null +++ b/src/utils/get-keys.ts @@ -0,0 +1,6 @@ + +const keys = { + shodan: process.env.SHODAN_API_KEY, +}; + +export default keys; diff --git a/src/utils/result-processor.ts b/src/utils/result-processor.ts new file mode 100644 index 0000000..0f390ee --- /dev/null +++ b/src/utils/result-processor.ts @@ -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; +};