MacAddress を 16 進文字列に変換してから、Java でバイトに解析するにはどうすればよいですか? 同様にIPアドレスも?
ありがとうございました
MAC アドレスはすでに 16 進数形式になっており、2 桁の 16 進数が 6 組になった形式になっています。
String macAddress = "AA:BB:CC:DD:EE:FF";
String[] macAddressParts = macAddress.split(":");
// convert hex string to byte values
Byte[] macAddressBytes = new Byte[6];
for(int i=0; i<6; i++){
Integer hex = Integer.parseInt(macAddressParts[i], 16);
macAddressBytes[i] = hex.byteValue();
}
と...
String ipAddress = "192.168.1.1";
String[] ipAddressParts = ipAddress.split("\\.");
// convert int string to byte values
Byte[] ipAddressBytes = new Byte[4];
for(int i=0; i<4; i++){
Integer integer = Integer.parseInt(ipAddressParts[i]);
ipAddressBytes[i] = integer.byteValue();
}