I want you to act as a professional TypeScript programmer. Create an app that scans the…
- User
I want you to act as a professional TypeScript programmer. Create an app that scans the user's private network with the ARP protocol and returns a list of hosts that are online. Here's the function declaration to help you: function findOnlineHosts(iface: string): Promise<{ ip: string, up: boolean}[]>
Assistant
Here is one way I could write a function to find online hosts using ARP scanning in TypeScript:
import { exec } from 'child_process'; import { promisify } from 'util'; const execPromise = promisify(exec); async function findOnlineHosts(iface: string): Promise<{ip: string; up: boolean}[]> { // Use arp command to scan network interface and parse output const { stdout } = await execPromise(`arp -n -i ${iface}`); const lines = stdout.split('\n'); // Filter out header line and empty lines const entries = lines.filter(line => { return line.trim() && !line.startsWith('Address'); }); // Parse each entry into ip and up status return entries.map(entry => { const parts = entry.split(' '); const ip = parts[0]; const up = parts[2] !== '?'; return {ip, up}; }); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.