Detecting the current IP through chrome extension?

后端 未结 3 1077
情书的邮戳
情书的邮戳 2021-01-15 01:54

My Chrome extention needs to know what is the IP of the machine that it is running on (the real world IP) Is there a easy way of doing it?

3条回答
  •  离开以前
    2021-01-15 02:29

    You could always use the freegeoip service, one of my favorite implementations to pull it in is as follows:

    var geoip = function(data){
        if (data.region_name.length > 0) {
            console.log('Your external IP:', data.ip);
        }
    }
    var el = document.createElement('script');
    el.src = 'http://freegeoip.net/json/?callback=geoip';
    document.body.appendChild(el);
    

提交回复
热议问题