import { filter_object } from "utility"; import { NetworkInterfaceInfo, networkInterfaces } from "os"; import { IPSubnetwork, IPv4 } from "ip-matching"; import { promise as ping_promise } from "ping"; const probe = ping_promise.probe; export function get_network_interfaces() { const invalid_network_interfaces = [ "lo" ]; const nw_interfaces = networkInterfaces() as Record; return filter_object( nw_interfaces, (name, opt_info) => { return !invalid_network_interfaces.includes(name) && opt_info !== undefined; } ) as Record; } export async function ping_subnetwork(subnetwork: IPSubnetwork) { const first_ip = subnetwork.getFirst() as IPv4; let current_ip = first_ip.getNext(); while(current_ip !== undefined && subnetwork.matches(current_ip)) { const current_ip_str = current_ip.toString(); const ping_result = await probe(current_ip_str, { timeout: 0.1 }); console.log(`${current_ip_str}${ping_result.alive ? " - Alive" : ""}`); current_ip = current_ip.getNext(); } }