Created
July 8, 2021 07:00
-
-
Save elzup/a324b8d1129dc00d076870565670eea9 to your computer and use it in GitHub Desktop.
Check is home Network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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