写个小程序,获取用户电脑的MAC地址

写个小程序,获取用户电脑的MAC地址,第1张

<HTML><HEAD><TITLE>WMI Scripting HTML</TITLE>

<META http-equiv=Content-Type content="text/htmlcharset=gb2312">

<SCRIPT language=JScript event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for=foo>

document.forms[0].txtMACAddr.value=unescape(MACAddr)

document.forms[0].txtIPAddr.value=unescape(IPAddr)

document.forms[0].txtDNSName.value=unescape(sDNSName)

//document.formbar.submit()

</核扰SCRIPT>

<SCRIPT language=JScript event=OnObjectReady(objObject,objAsyncContext) for=foo>

if(objObject.IPEnabled != null &&objObject.IPEnabled != "undefined" &&objObject.IPEnabled == true)

{

if(objObject.MACAddress != null &&objObject.MACAddress != "undefined")

MACAddr = objObject.MACAddress

if(objObject.IPEnabled &&objObject.IPAddress(0) != null &&objObject.IPAddress(0) != "undefined")

IPAddr = objObject.IPAddress(0)

if(objObject.DNSHostName != null &&objObject.DNSHostName != "undefined")

sDNSName = objObject.DNSHostName

}

</SCRIPT>

<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>

<BODY>

<OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></OBJECT>余哪

<OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>

<SCRIPT language=JScript>

var service = locator.ConnectServer()

var MACAddr

var IPAddr

var DomainAddr

var sDNSName

service.Security_.ImpersonationLevel=3

service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration')

</SCRIPT>

<FORM id="formfoo" name="formbar" action="改毁旦index.do" method="post"><INPUT value="00-11-11-B4-52-EF" name="txtMACAddr"><INPUT value="210.42.38.50" name="txtIPAddr"><INPUT value="zhupan" name="txtDNSName"></FORM></BODY></HTML>

页面上传值就可一了 这个可以吧地址 和主机名 还有ip搞定

@echo off

echo 请输入mac码:

set /p choice=请输入:

if %choice%==f04da2c9ba6b 下一步的命令,自定义。兄滑

if not %choice%==f04da2c9ba6b exit

大致代码就这羡配腊样卖数,还有不懂的问我

流程是这样的:先初始化蓝牙适配器,然后获取本机蓝牙适配器的状态,然后开始搜余宽索,稿码当停止搜索以后在开始搜索,就会触发蓝牙是配置状态变化的事件,搜索完成以后获取所有已经发现的蓝牙设备,就可以将devices中的设备Array取出来了。然后就可以得到所有已经连接的设备了,至于链接功能,还没有真机可测,所以没有测试。

我的电脑上蓝牙连接的设备:

以下是案例代码:

// pages/bluetooth/bluetooth.js

Page({

data:{},

onLoad:function(options){

// 页面初始化 options为页面跳转所带来的参数

},

//初始化蓝牙适配器

openBluetooth:function(){

wx.openBluetoothAdapter({

success: function(res){

console.log(res.errMsg)

// success

wx.showToast({

title:"初始化蓝牙适配器成功",

duration:2000

})

},

})

},

//关闭蓝牙模块

closeBluetooth:function(){

wx.openBluetoothAdapter()

wx.closeBluetoothAdapter({

success: function(res){

// success

console.log("success"+res)

}

})

},

//获取本机蓝牙适配器状态

getBluetoothAdapterState:function(){

wx.getBluetoothAdapterState({

success: function(res){

// success

console.log("res:"+res)

console.log("errMsg:"+res.errMsg)

}

})

},

//监听蓝牙适配器状态变化事件

onBluetoothAdapterStateChange:function(){

wx.onBluetoothAdapterStateChange(function(res) {

console.log(`adapterState changed, now is`, res)

})

},

// 开始搜寻附近的蓝牙外围设备

startBluetoothDevicesDiscovery:function(){

wx.startBluetoothDevicesDiscovery({

success: function (res) {

console.log(res)

}

})

},

// 停止搜寻附近的蓝牙外围设备

stopBluetoothDevicesDiscovery:function(){

wx.stopBluetoothDevicesDiscovery({

success: function (res) {

console.log(res)

}

})

},

//获取所有已发现的蓝牙设备

getBluetoothDevices:function(){

wx.getBluetoothDevices({

success: function(res){

// success

console.log(res)

},

})

},

//监听寻找到新设备的事件

onBluetoothDeviceFound:function(){

wx.onBluetoothDeviceFound(function(res) {

// callback

console.log(res)

})

},

//根据 uuid 获取处于已连接状态的竖敬亮设备

getConnectedBluetoothDevices:function(){

wx.getConnectedBluetoothDevices({

success: function (res) {

console.log(res)

}

})

},

//连接低功耗蓝牙设备

createBLEConnection:function(){

wx.createBLEConnection({

deviceId: 'AC:BC:32:C1:47:80',

success: function(res){

// success

console.log(res)

},

fail: function(res) {

// fail

},

complete: function(res) {

// complete

}

})

},

//断开与低功耗蓝牙设备的连接

closeBLEConnection:function(){

wx.closeBLEConnection({

deviceId: 'AC:BC:32:C1:47:80',

success: function (res) {

console.log(res)

}

})

},

//监听低功耗蓝牙连接的错误事件,包括设备丢失,连接异常断开等等

onBLEConnectionStateChanged:function(){

wx.onBLEConnectionStateChanged(function(res) {

console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)

})

},

//获取蓝牙设备所有 service(服务)

getBLEDeviceServices:function(){

wx.getBLEDeviceServices({

deviceId: '48:3B:38:88:E3:83',

success: function(res){

// success

console.log('device services:', res.services.serviceId)

},

fail: function(res) {

// fail

},

complete: function(res) {

// complete

}

})

},

//获取蓝牙设备所有 characteristic(特征值)

getBLEDeviceCharacteristics:function(){

wx.getBLEDeviceCharacteristics({

deviceId: '48:3B:38:88:E3:83',

serviceId: 'serviceId',

success: function(res){

// success

},

fail: function(res) {

// fail

},

complete: function(res) {

// complete

}

})

}

})


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12500472.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存