通过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. Netty 系列一(核心组件和实例).

    一.概念 早期的 Java API 只支持由本地系统套接字库提供所谓的阻塞函数来支持网络编程.由于是阻塞 I/O ,要管理多个并发客户端,需要为每个新的客户端Socket 创建一个 Thread .这 ...

  2. JS实现异步提交

    什么是XMLHttpRequest? XMLHttpRequest对象用于在后台与服务器交换数据 XMLHttpRequst的作用 在不重新加载页面的情况下更新网页 在页面已加载后从服务器请求数据 在 ...

  3. PHP Warning: PHP Startup: redis: Unable to initialize module Windows版本phpredis扩展

    版权声明:经验之谈,不知能否换包辣条,另,转载请注明出处.https://www.cnblogs.com/zmdComeOn/category/1295248.html [root@VM_0_2_ce ...

  4. Tomcat post参数长处理

    如下图所示:增加maxPostSize="-1"属性即可

  5. input的type类型

    对部分生僻的input属性值解释: type="reset": 可以一键清空form表单里面所有的数据 <form> <input type="text ...

  6. Linux Linux下最大文件描述符设置

    Linux下最大文件描述符设置 by:授客 QQ:1033553122 1.   系统可打开最大文件描述符设置 查看系统可打开最大文件描述符 # cat /proc/sys/fs/file-max 6 ...

  7. Kotlin入门(28)Application单例化

    Application是Android的又一大组件,在App运行过程中,有且仅有一个Application对象贯穿应用的整个生命周期,所以适合在Application中保存应用运行时的全局变量.而开展 ...

  8. springboot 学习之路 7(静态页面自动生效问题)

    目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...

  9. elasticsearch及head插件安装与配置

    1. 环境软件版本说明 系统:ubuntu14.04.1 JDK:1.8 elasticsearch:5.5.2 node:9.11.1 elasticsearch:5.X 2. 环境软件下载说明 1 ...

  10. 用百度地图API分析打交通大数据

    百度地图API, 文档不全,例子不细致. 在网上还没有太多有用的例子.比如说下面几个需求的解决方案就找不到: 1. 如何用百度地图API查询一个地点的经纬度. 2. 如何用百度地图通过一个经纬度查询商 ...