try {
ip = InetAddressgetLocalHost();
NetworkInterface network = NetworkInterfacegetByInetAddress(ip);
if (network != null) {
byte[] mac = networkgetHardwareAddress();
if(mac != null) {
Systemoutprint("MAC address : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < maclength; i++) {
sbappend(Stringformat("%02X%s", mac[i], (i < maclength - 1) "-" : ""));
}
Systemoutprintln(sbtoString());
}
} catch (UnknownHostException e) {
eprintStackTrace();
} catch (SocketException e) {
eprintStackTrace();
}
import javanet;
public class NetInfo {
public static void main(String[] args) {
new NetInfo()say();
}
public void say() {
try {
InetAddress i = InetAddressgetLocalHost();
Systemoutprintln(i); //计算机名称和ip
Systemoutprintln(igetHostName()); //名称
Systemoutprintln(igetHostAddress()); //只获得ip
}
catch(Exception e){eprintStackTrace();}
}
}
以上就是关于在linux用java根据ip获得mac地址全部的内容,包括:在linux用java根据ip获得mac地址、java 获取本机Ip地址和对应的mac地址、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)