如何使用JavaScript或jQuery在cmd中的ipconfig中获取本地系统IP



我使用下面的代码来获取系统本地ip,但没有获得它,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
function callback(response)
{

console.log(response);
document.getElementById("data").innerHTML=response.IPv4;
}
$.ajax({

url:"https://geoip-db.com/jsonp/",
dataType:"jsonp"
})
</script

我也用过这个代码

<script type="text/javascript">

var ip='<%=request.getRemoteHost()%>';
document.getElementById('list1').innerHTML = ip;


var ip1='<%=request.getRemoteAddr()%>';
document.getElementById('list2').innerHTML = ip1;

var ip2='<%=request.getLocalAddr()%>';
document.getElementById('list3').innerHTML = ip2;

</script> 

I have also used the below code but I am not getting the IP that we get from inconfig from the command prompt

<script>  
$(document).ready(function ubsrt()
{
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;  
var pc = new RTCPeerConnection({iceServers:[]}), 
noop = function(){}; 

pc.createDataChannel("");  
pc.createOffer(pc.setLocalDescription.bind(pc), noop);   
pc.onicecandidate = function(ice){ 
if(!ice || !ice.candidate || !ice.candidate.candidate)  return;
var myIP = /([0-9]{1,3}(.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)[1];
console.log('my IP: ', myIP); 
$('.ipAdd').text(myIP);
alert("IP: "+myIP);
pc.onicecandidate = noop;

}; 
});
</script> 

我想要与使用javascript的ipconfig相同的IP。我用了很多代码来查找IP,但它不是我从IPCONFIg 获得的IP

使用此:

function callback(response) {
console.log(response);
document.getElementById("data").innerHTML = response.IPv4;
}
$.ajax({
url: "https://geoip-db.com/jsonp/",
dataType: "jsonp"
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p id="data"></p>

最新更新