Skip to content

Instantly share code, notes, and snippets.

@z4vmk
Created October 15, 2024 03:40
Show Gist options
  • Save z4vmk/e90f701184f29bbd601b6d6d76f75d1e to your computer and use it in GitHub Desktop.
Save z4vmk/e90f701184f29bbd601b6d6d76f75d1e to your computer and use it in GitHub Desktop.
HD Example Three
// Dependencies
import wifi from "npm:node-wifi";
import { Hono } from "jsr:@hono/hono";
// Create App
const app = new Hono(); // Creates a new Hono instance.
wifi.init({
// Initiates the Node Wifi library.
iface: null,
});
// Scan Internet Function
// This function will scan Wifi Networks on the local machine and return them in an array.
// It will also return the current network the device is on currently.
async function scanInternet() {
const foundNetworks = await wifi.scan().catch((_e: Error) => {
return [];
});
const currentNetwork = await wifi
.getCurrentConnections()
.catch((_e: Error) => {
return {};
});
return { networks: foundNetworks, currentnetwork: currentNetwork[0] };
}
app.get("/wifi", async (c) => {
const scannedNetworks = await scanInternet();
return c.json(scannedNetworks);
});
// Serve App
Deno.serve(app.fetch); // Serves the Hono instance via Deno.Serve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment