가상 라우터를 프로그래밍 중입니다. 그리고 첫 번째 임무는 이더넷 프레임을 만드는 것입니다. 현재 MAC 소스 주소를 얻으려고합니다. 내 컴퓨터에서 사용되는 모든 MAC 주소를 가져 오는 코드가 있지만 가상 호스트 네트워크가있어 코드에서이 MAC 주소를 가져 오는 것입니다. 이더넷 프레임에 어떤 MAC 주소를 사용해야하는지 프로그래밍 방식으로 결정하는 데 문제가 있습니다. 이것은 현재 코드입니다올바른 비 가상 MAC 주소를 자바로 가져 오기
private byte[] grabMACAddress(){
try{
InetAddress[] addresses = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
for(int i = 0; i < addresses.length; i++){
NetworkInterface ni = NetworkInterface.getByInetAddress(addresses[i]);
mac = ni.getHardwareAddress();
if (mac != null){
for(int j=0; j < mac.length; j++) {
String part = String.format("%02X%s", mac[j], (j < mac.length - (1)) ? "" : "");
s += part;
}
System.out.println();
}
else{
System.out.println("Address doesn't exist or is not accessible.");
}
}
}
catch(IOException e){
}
System.out.println(s);
return mac;
}
고마워요! 내가 당신의 기술을 사용하여 공용 서버에 연결했습니다. 그것은 매력처럼 작동했습니다. –