How to get my external IP address with node.js?

后端 未结 14 1507
情深已故
情深已故 2020-12-06 05:00

I\'m using node.js and I need to get my external IP address, provided by my ISP. Is there a way to achieve this without using a service like http://myexternalip.com/raw ?

14条回答
  •  感情败类
    2020-12-06 05:36

    npm install --save public-ip from here.

    Then

    publicIp.v4().then(ip => {
      console.log("your public ip address", ip);
    });
    

    And if you want the local machine ip you can use this.

    var ip = require("ip");
    var a = ip.address();
    console.log("private ip address", a);
    

提交回复
热议问题