A tiny node.js module to get your local and public ip adresses.
npm install getyourip
git clone https://github.com/FISHERDAY/getyourip
Get your local and public ip addresses immediately.
let ip = require('getyourip');
console.log(ip.getLocalIp());
//=> '192.168.1.108'
console.log(await ip.getPublicIp());
//=> '77.120.70.179'
Returns a <string>
with your private IPv4 address.
Returns a Promise with your public IPv4 address.
Module uses os.networkInterfaces()
method from built-in Node.js module os
to get local ip. It returns an object containing network interfaces that have been assigned a network address. Than it gets the local IP address by checking .family
and .internal
properties. To get public ip module uses http.get(url[, options][, callback])
method from built-in Node.js module http
which sends a request to api.ipify.org
.