简体   繁体   中英

How to get My PUBLIC IP address Using Node js

I want to get my Public IP address using Node js only

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM