Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check is home Network
import fs from 'fs'
import { promisify } from 'util'
import network from 'network'
const getActiveInterface = promisify(network.get_active_interface)
const getCurrent = async () => (await getActiveInterface())?.mac_address
const SAVE_FILE = 'home.mac.txt'
const saveHomeNetwork = (id: string) => fs.writeFileSync('home.mac.txt', id)
const loadHomeNetwork = () => fs.readFileSync(SAVE_FILE, 'utf-8').trim()
const isSameNetwork = async (mac: string) => mac === (await getCurrent())
const isHomeNetwork = () => isSameNetwork(loadHomeNetwork())
async function _setupHome() {
const currntAccessPointMacAddress = await getCurrent()
console.log(currntAccessPointMacAddress)
saveHomeNetwork(currntAccessPointMacAddress)
}
async function main() {
console.log(await isHomeNetwork())
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment