javascript - 如何使用 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>
推荐阅读
- javascript - 在谷歌表格中,如何将 A 列中的 #N/A 替换为 B 列中的相应值
- wordpress - 仅在插件更新时显示管理员通知
- java - 在 ArrayList 中查找匹配项的 Java 方法
- python - 如何解释这个 fft 图
- bash - 如何在bash中将4-e7转换为十进制?
- arrays - 有什么方法可以将变量分配给 axios 请求并在 onUploadProgress 中访问它
- python - Python没有将值返回给函数中的变量
- php - 我该如何解决这个问题 页面不工作 HTTP ERROR 500
- android - 防止 ScrollView 中的子项被滚动出屏幕
- c# - 从 C# 控制台应用程序中的 Powershell 脚本读取 json 数据