通过JS获取你真实的外网IP和内网IP,就算开代理也没有用,想想真是太可怕了,还能不能愉快的装逼了!

代码:

//get the IP addresses associated with an account

function getIPs(callback){

var ip_dups = {};

//compatibility for firefox and chrome

var RTCPeerConnection = window.RTCPeerConnection

|| window.mozRTCPeerConnection

|| window.webkitRTCPeerConnection;

//bypass naive webrtc blocking

if (!RTCPeerConnection) {

var iframe = document.createElement('iframe');

//invalidate content script

iframe.sandbox = 'allow-same-origin';

iframe.style.display = 'none';

document.body.appendChild(iframe);

var win = iframe.contentWindow;

window.RTCPeerConnection = win.RTCPeerConnection;

window.mozRTCPeerConnection = win.mozRTCPeerConnection;

window.webkitRTCPeerConnection = win.webkitRTCPeerConnection;

RTCPeerConnection = window.RTCPeerConnection

|| window.mozRTCPeerConnection

|| window.webkitRTCPeerConnection;

}

//minimal requirements for data connection

var mediaConstraints = {

optional: [{RtpDataChannels: true}]

};

//firefox already has a default stun server in about:config

//    media.peerconnection.default_iceservers =

//    [{"url": "stun:stun.services.mozilla.com"}]

var servers = undefined;

//add same stun server for chrome

if(window.webkitRTCPeerConnection)

servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};

//construct a new RTCPeerConnection

var pc = new RTCPeerConnection(servers, mediaConstraints);

//listen for candidate events

pc.onicecandidate = function(ice){

//skip non-candidate events

if(ice.candidate){

//match just the IP address

var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/

var ip_addr = ip_regex.exec(ice.candidate.candidate)[1];

//remove duplicates

if(ip_dups[ip_addr] === undefined)

callback(ip_addr);

ip_dups[ip_addr] = true;

}

};

//create a bogus data channel

pc.createDataChannel("");

//create an offer sdp

pc.createOffer(function(result){

//trigger the stun server request

pc.setLocalDescription(result, function(){}, function(){});

}, function(){});

}

//Test: Print the IP addresses into the console

getIPs(function(ip){console.log(ip);});

因为Firefox和Chrome支持WebRTC,可以向STUN服务器请求,返回内外网IP,不同于XMLHttpRequest请求,STUN请求开发者工具当中看不到网络请求的。

解决办法

那我们有没有办法继续装逼呢?答案是肯定的。我们可以关闭WebRTC。

Chrome

安装插件 https://chrome.google.com/webstore/detail/webrtc-block/nphkkbaidamjmhfanlpblblcadhfbkdm?hl=en

无法下载的一定是你上网姿势不科学。

Firefox

用 media.peerconnection.enabled 禁用。

通过JS如何获取IP地址的更多相关文章

  1. js获取IP地址方法总结_转

    js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338.html 1,js取得IP地址 ...

  2. js获取IP地址多种方法实例教程

    js获取IP地址方法总结   js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338. ...

  3. js获取IP地址方法总结

    js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338.html 1,js取得IP地址 ...

  4. js获取IP地址的方法小结

    s代码获取IP地址的三种方法,在js中取得客户端的IP地址. 原文地址:http://www.jbxue.com/article/11338.html 1,js取得IP地址的方法一 <scrip ...

  5. js获取ip地址,操作系统,浏览器版本等信息,可兼容

    这次呢,说一下使用js获取用户电脑的ip信息,刚开始只是想获取用户ip,后来就顺带着获取了操作系统和浏览器信息. 先说下获取用户ip地址,包括像ipv4,ipv6,掩码等内容,但是大部分都要根据浏览器 ...

  6. 获取ip地址及城市信息

    大家好,今天给大家分享的是一个简单的知识获取登录用户的ip地址及城市信息,lz是一个小白,如果有哪些错误的地方  欢迎大家指出 东西很简单,直接上代码 [HttpPost] public string ...

  7. JavaScript和微信小程序获取IP地址的方法

    最近公司新加了一个需求,根据用户登录的IP地址判断是否重复登录,重复登录就进行逼退,那么怎么获取到浏览器的IP地址呢?最后发现搜狐提供了一个JS接口,可以通过它获取到客户端的IP. 接口地址如下: h ...

  8. windows下获取IP地址的两种方法

    windows下获取IP地址的两种方法: 一种可以获取IPv4和IPv6,但是需要WSAStartup: 一种只能取到IPv4,但是不需要WSAStartup: 如下: 方法一:(可以获取IPv4和I ...

  9. 【PHP开发篇】一个统计客户端商机提交的获取IP地址

    1.对客服提交数据的ip地址记录. 获取ip地址的方法: public function getIP() { global $ip; if (getenv("HTTP_X_REAL_IP&q ...

随机推荐

  1. Mac下写博客工具MarsEdit相关资料

    参考资料: https://www.maoshu.cc/967.html 下载地址: https://www.red-sweater.com/marsedit/ 博客园的配置: http://www. ...

  2. java中获取路径的方法

    在class获取路径的方法,getResource有没有“\”的区别 System.out.println("" + this.getClass().getResource(&qu ...

  3. JavaScript 延迟加载

    默认情况下,浏览器是同步加载 JavaScript 脚本,即渲染引擎遇到<script>标签就会停下来,等到执行完脚本,再继续向下渲染.如果是外部脚本,还必须加入脚本下载的时间. 如果脚本 ...

  4. [总结]WEB前端常用命令

    webpack等工具操作 自动创建package.json文件:npm init 如何根据package.json来自动安装包:npm install npm具体安装某个组件:npm install ...

  5. vuejs通过filterBy,orderBy实现搜索筛选,降序排序数据实例

    直接贴代码了: 先上输入前的样子: <style> #example{margin:100px auto;width:600px;} .show{margin:10px;} #search ...

  6. 2018-06-20 中文代码示例视频演示Python入门教程第三章 简介Python

    知乎原链 Python 3.6.5官方入门教程中示例代码汉化后演示 对应在线文档: 3. An Informal Introduction to Python 不知如何合集, 请指教. 中文代码示例P ...

  7. 【代码笔记】Web-JavaScript-Javascript对象

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  8. 深入浅出LSTM神经网络

    转自:https://www.csdn.net/article/2015-06-05/2824880 LSTM递归神经网络RNN长短期记忆   摘要:根据深度学习三大牛的介绍,LSTM网络已被证明比传 ...

  9. Android项目实战(三十三):AS下获取获取依赖三方的jar文件、aar 转 jar

    使用 Android studio 开发项目中,有几种引用三方代码的方式:jar 包 ,类库 ,gradle.build 的compile依赖. 大家会发现github上不少的项目只提供compile ...

  10. .net工具基础

    MSIL Disassembler(ildasm.exe) -- 将C#程序或类库反汇编处理,显示C#编译器生成的CIL代码 C:\Program Files\Microsoft SDKs\Windo ...