如何通过js获取本机ip?


一、引入依赖包

const axios = require('axios')

  

二、请求接口

/**
 * 请求接口
 */
async function getIP () {
  const { data } = await axios.request({
    url: 'https://api.ipify.org/?format=json',
    method: 'get'
  })
  const ip = _.get(data, 'ip', '')
  return ip
}

 

三、获取IP

 const ip = await getIP()

 console.log('----本机IP为----',ip)

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM