zoukankan      html  css  js  c++  java
  • 获取本地客户端ip 局域网ip 物理地址mac 主机名

    此方法适用于IE浏览器.无需联网即可查询.

    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <head>
    
    <title></title>
    
    </head>
    
    <body>
    
    <object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" style="display:none;visibility:hidden"></object>
    
    <object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo" style="display:none;visibility:hidden"></object>
    
    <form name="myForm">
    
    <br/>MAC地址:<input type="text" name="macAddress">
    
    <br/>IP地址:<input type="text" name="ipAddress">
    
    <br/>主机名:<input type="text" name="hostName">
    
    </form>
    
    </body>
    
    </html>
    
    <script language="javascript">
    
    var sIPAddr="";
    
    var sDNSName="";
    
    var service = locator.ConnectServer();
    
    service.Security_.ImpersonationLevel=3;
    
    service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
    
    </script>
    
    <script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript">
    
             if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true){
    
                               if(objObject.IPEnabled && objObject.IPAddress(0) !=null && objObject.IPAddress(0) != "undefined")
    
                                             sIPAddr = objObject.IPAddress(0);
    
                               if(objObject.MACAddress != null &&objObject.MACAddress != "undefined")
    
                         sMacAddr = objObject.MACAddress;
    
                               if(objObject.DNSHostName != null &&objObject.DNSHostName != "undefined")
    
                                             sDNSName = objObject.DNSHostName;
                                             console.log(sIPAddr);
    
              }
    
    </script>
    
    <script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">
    
    myForm.macAddress.value=sMacAddr;
    
    myForm.ipAddress.value=sIPAddr;
    
    myForm.hostName.value=sDNSName;
    
    </script>

    网页效果:允许控件执行.(此窗口在项目中运行,可以在ie Internet选项-安全-受信任站点-站点-添加 进行设置,以及自定义级别内的ActiveX的相关设置,设置之后就不再弹出提示框);

    ip地址可能有多个:如局域网网的ip,无线网卡的ip等.可在控制台刷新页面查看所有的ip地址.

  • 相关阅读:
    C# 多线程详解 Part.02(UI 线程和子线程的互动、ProgressBar 的异步调用)
    ubuntu 18.04安装ftp服务器
    ubuntu 18.04设置开机自动挂载移动硬盘
    使用apache commons net进行ftp传输
    Navicat连接MySQL 8出现2059
    Eclipse配置tomcat
    MySQL从.ibd文件中恢复数据
    MySQL建表时添加备注以及查看某一张表的备注信息
    在node.js中使用Set
    Java测试当前应用所占用的内存示例
  • 原文地址:https://www.cnblogs.com/s-xl/p/7983459.html
Copyright © 2011-2022 走看看