Skip to content

Instantly share code, notes, and snippets.

@elzup
Created July 8, 2021 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elzup/a324b8d1129dc00d076870565670eea9 to your computer and use it in GitHub Desktop.
Save elzup/a324b8d1129dc00d076870565670eea9 to your computer and use it in GitHub Desktop.
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