def genMacIp(): (String, String) = {
val ipArr: Array[Int] = new Array[Int](4)
for (i <- 0 to ipArr.length - 1) {
var rdInt: Int = Random.nextInt(256)
while (i == 2 && rdInt % 2 == 1) {
rdInt = Random.nextInt(256)
}
if (i == 1 && rdInt == 0) rdInt = 1
ipArr(i) = rdInt
}
val macArr: Array[Int] = new Array[Int](6)
val macStrArr: Array[String] = new Array[String](6)
for (i <- 0 to macArr.length - 1) {
macArr(i) = ipArr(i % 4)
}
for (i <- 0 to macArr.length - 1) {
var hexStr: String = Integer.toHexString(macArr(i)).toUpperCase()
if (macArr(i) < 16) {
hexStr = "0" + hexStr
}
macStrArr(i) = hexStr
}
val mac: String = macStrArr.mkString(":")
val ip: String = ipArr.mkString(".")
(mac, ip)
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29