日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

kotlin获取属性_Kotlin程序获取系统MAC地址

發(fā)布時(shí)間:2023/12/1 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kotlin获取属性_Kotlin程序获取系统MAC地址 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

kotlin獲取屬性

The task is to get system MAC address.

任務(wù)是獲取系統(tǒng)MAC地址。

package com.includehelpimport java.net.InetAddress import java.net.NetworkInterface//Function to get System MAC fun getSystemMac(): String? {return try {val OSName = System.getProperty("os.name") //Get Operating System Nameif (OSName.contains("Windows")) {getMAC4Windows() // Call if OS is Windows} else {var mac = getMAC4Linux("eth0")if (mac == null) {mac = getMAC4Linux("eth1")if (mac == null) {mac = getMAC4Linux("eth2")if (mac == null) {mac = getMAC4Linux("usb0")}}}mac}} catch (E: Exception) {System.err.println("System Mac Exp : " + E.message)null} }/*** Method for get MAc of Linux Machine*/ fun getMAC4Linux(name: String): String? {return try {val network = NetworkInterface.getByName(name)val mac = network.hardwareAddressval sb = StringBuilder()for (i in mac.indices) {sb.append(String.format("%02X%s", mac[i], if (i < mac.size - 1) "-" else ""))}sb.toString()} catch (E: Exception) {System.err.println("System Linux MAC Exp : " + E.message)null} }/*** Method for get Mac Address of Windows Machine */ fun getMAC4Windows(): String? {return try {val addr = InetAddress.getLocalHost()val network = NetworkInterface.getByInetAddress(addr)val mac = network.hardwareAddressval sb = StringBuilder()for (i in mac.indices) {sb.append(String.format("%02X%s", mac[i], if (i < mac.size - 1) "-" else ""))}sb.toString()} catch (E: Exception) {System.err.println("System Windows MAC Exp : " + E.message)null} }//Main Function, Entry Point of Program fun main(args: Array<String>) {//Call Function to get MAC Addressval macAddress = getSystemMac()//Print MAC Addressprintln("System Mac Address : $macAddress") }

Output

輸出量

System Mac Address : 02-12-FE-11-00-05

翻譯自: https://www.includehelp.com/kotlin/get-system-mac-address.aspx

kotlin獲取屬性

總結(jié)

以上是生活随笔為你收集整理的kotlin获取属性_Kotlin程序获取系统MAC地址的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。