Skip to content
Advertisement

How to get My PUBLIC IP address Using Node js

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 …

Advertisement

Answer

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

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement