I want to get my Public IP address using Node js only
For example when i search on Google "What is my Ip address "
Gives me output like 10X.XX.XX.XXX
How to get this Ip address Using node js without importing any Libraries like ip , Public-ip etc ...
I want to write my Custom Code to get public ip Without sending requests to other websites like whatismyipaddress.com , ipconfig.com etc ...
const { exec } = require('child_process')
exec('curl ip-adresim.app', function(error, stdout, stderr){
if(error)
return;
console.log('your ip is :'+ stdout);
})
you could run a command and get the output like curl or ping
There is no native way to get the public IP, in fact, there is no way to get it from your server, not even from the Linux command, you have to ask an external server, and this package does exactly so with different servers.
I understand you don't want to ask an external library or an external server, but you have no choice.
Im suggesting using an external library, because it takes care of asking multiple servers instead of just one in the case that one goes offline
You can try this package it works perfectly