Repository navigation
Expand file tree
/
Copy pathexample.js
More file actions
60 lines (47 loc) · 2.58 KB
/
Copy pathexample.js
File metadata and controls
60 lines (47 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import CheckHost from '@check-hostcc/check-host-api';
// Initialize the API wrapper.
// You can optionally pass your API token here to bump your rate limits; it
// is sent as an Authorization: Bearer header.
// Example: const api = new CheckHost({ token: 'YOUR_API_TOKEN_UUID' });
const api = new CheckHost();
async function runExamples() {
try {
console.log('--- Check-Host API Demonstration ---');
// 1. Fetch available nodes globally (GET)
console.log('\n1. Fetching available global locations...');
const locations = await api.locations();
// The API returns a large Object for locations, we just print the keys representing nodes
console.log(`Successfully retrieved ${Object.keys(locations).length} locations!`);
// 2. Perform a Ping check on a host (POST) with optional parameters
console.log('\n2. Initiating Ping task to 8.8.8.8 in DE and NL...');
const pingTask = await api.ping('8.8.8.8', {
region: ['DE', 'NL'], // Filter nodes by ISO Country Code
repeatchecks: 2 // Send 2 packets from each node
});
console.log(`Task Created! UUID: ${pingTask.uuid}`);
console.log('Waiting 2 seconds for nodes to execute the ping request...');
// Wait for nodes to execute checks (2-3 seconds is optimal)
await new Promise(resolve => setTimeout(resolve, 2000));
// 3. Retrieve the results of the Ping check (GET)
console.log('\n3. Fetching Ping Report results...');
const reportResult = await api.report(pingTask.uuid);
console.log('--- Results Snippet ---');
// We print just a snippet of the potentially massive JSON response
console.log(JSON.stringify(reportResult, null, 2).substring(0, 300) + '\n... (truncated)');
// 4. Passive Network Intelligence - no check dispatched, instant result
console.log('\n4. Looking up intelligence for 1.1.1.1...');
const intel = await api.ipIntel('1.1.1.1');
const bgp = intel.data.bgp || {};
console.log(`AS${bgp.asn} ${bgp.as_name} (${bgp.prefix}), RPKI ${bgp.rpki_status}`);
// 5. Port exposure across the scanned Internet
console.log('\n5. Checking how widespread port 443 is...');
const port = await api.portIntel(443);
console.log(`${port.well_known}: ${port.data.open_ips} open IPs worldwide`);
console.log('\nDemonstration complete!');
} catch (error) {
console.error('\nAn active error occurred during the demonstration:');
console.error(error.message);
}
}
// Run the demo
runExamples();