import java.net.SocketException;
import java.util.Enumeration;
/**
-
@Program: hy-utils @ClassName: StuNetworkInterface @Author: huyi @Date: 2020-09-20
-
23:48 @Description: 网络接口 @Version: V1.0
*/
public class NetworkInterfaceUtil {
public static void main(String[] args) {
try {
Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaces.nextElement();
System.out.println(“getName获得网络设备现实名称=” + networkInterface.getName());
System.out.println(“getDisplayName获得网络设备现实名称=” + networkInterface.getDisplayName());
System.out.println(“getIndex获得网络接口的索引=” + networkInterface.getIndex());
System.out.println(“isUp是否已经开启并运行=” + networkInterface.isUp());
System.out.println(“isLoopback是否为回调接口=” + networkInterface.isLoopback());
System.out.println(“getMTU获得最大传输单元=” + networkInterface.getMTU());
Enumeration enumerations = networkInterface.getInetAddresses();
while (enumerations.hasMoreElements()) {
InetAddress inetAddress = enumerations.nextElement();
System.out.println(“获取此IP地址的完全限定域名=” + inetAddress.getCanonicalHostName());
System.out.println(“获取此IP地址的主机名=” + inetAddress.getHostName());
System.out.println(“获取此IP地址的字符串=” + inetAddress.getHostAddress());
System.out.print(“getAddress返回此InetAddress对象的原始IP地址=”);
byte[] addressByte = inetAddress.getAddress();
for (byte b : addressByte) {
System.out.print(b + " ");
}
System.out.println();
}
System.out.println();
}
} catch (SocketException e) {
e.printStackTrace();
}
}
}
看看执行结果。
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/lib/tools.jar:/Users/huyi/idea/csdn/target/classes:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.5.5/spring-boot-starter-web-2.5.5.jar:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot-starter/2.5.5/spring-boot-starter-2.5.5.jar:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.5.5/spring-boot-starter-logging-2.5.5.jar:/Users/huyi/.m2/repository/ch/qos/logback/logback-classic/1.2.6/logback-classic-1.2.6.jar:/Users/huyi/.m2/repository/ch/qos/logback/logback-core/1.2.6/logback-core-1.2.6.jar:/Users/huyi/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.14.1/log4j-to-slf4j-2.14.1.jar:/Users/huyi/.m2/repository/org/apache/logging/log4j/log4j-api/2.14.1/log4j-api-2.14.1.jar:/Users/huyi/.m2/repository/org/slf4j/jul-to-slf4j/1.7.32/jul-to-slf4j-1.7.32.jar:/Users/huyi/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/huyi/.m2/repository/org/yaml/snakeyaml/1.28/snakeyaml-1.28.jar:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.5.5/spring-boot-starter-json-2.5.5.jar:/Users/huyi/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.12.5/jackson-databind-2.12.5.jar:/Users/huyi/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.12.5/jackson-annotations-2.12.5.jar:/Users/huyi/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.12.5/jackson-core-2.12.5.jar:/Users/huyi/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.12.5/jackson-datatype-jdk8-2.12.5.jar:/Users/huyi/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.12.5/jackson-datatype-jsr310-2.12.5.jar:/Users/huyi/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.12.5/jackson-module-parameter-names-2.12.5.jar:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.5.5/spring-boot-starter-tomcat-2.5.5.jar:/Users/huyi/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.53/tomcat-embed-core-9.0.53.jar:/Users/huyi/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.53/tomcat-embed-el-9.0.53.jar:/Users/huyi/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.53/tomcat-embed-websocket-9.0.53.jar:/Users/huyi/.m2/repository/org/springframework/spring-web/5.3.10/spring-web-5.3.10.jar:/Users/huyi/.m2/repository/org/springframework/spring-beans/5.3.10/spring-beans-5.3.10.jar:/Users/huyi/.m2/repository/org/springframework/spring-webmvc/5.3.10/spring-webmvc-5.3.10.jar:/Users/huyi/.m2/repository/org/springframework/spring-aop/5.3.10/spring-aop-5.3.10.jar:/Users/huyi/.m2/repository/org/springframework/spring-context/5.3.10/spring-context-5.3.10.jar:/Users/huyi/.m2/repository/org/springframework/spring-expression/5.3.10/spring-expression-5.3.10.jar:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot-devtools/2.5.5/spring-boot-devtools-2.5.5.jar:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot/2.5.5/spring-boot-2.5.5.jar:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.5.5/spring-boot-autoconfigure-2.5.5.jar:/Users/huyi/.m2/repository/org/springframework/boot/spring-boot-configuration-processor/2.5.5/spring-boot-configuration-processor-2.5.5.jar:/Users/huyi/.m2/repository/org/projectlombok/lombok/1.18.20/lombok-1.18.20.jar:/Users/huyi/.m2/repository/org/slf4j/slf4j-api/1.7.32/slf4j-api-1.7.32.jar:/Users/huyi/.m2/repository/org/springframework/spring-core/5.3.10/spring-core-5.3.10.jar:/Users/huyi/.m2/repository/org/springframework/spring-jcl/5.3.10/spring-jcl-5.3.10.jar:/Users/huyi/.m2/repository/com/aliyun/oss/aliyun-sdk-oss/3.10.2/aliyun-sdk-oss-3.10.2.jar:/Users/huyi/.m2/repository/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar:/Users/huyi/.m2/repository/org/apache/httpcomponents/httpcore/4.4.14/httpcore-4.4.14.jar:/Users/huyi/.m2/repository/commons-codec/commons-codec/1.15/commons-codec-1.15.jar:/Users/huyi/.m2/repository/org/jdom/jdom2/2.0.6/jdom2-2.0.6.jar:/Users/huyi/.m2/repository/org/codehaus/jettison/jettison/1.1/jettison-1.1.jar:/Users/huyi/.m2/repository/stax/stax-api/1.0.1/stax-api-1.0.1.jar:/Users/huyi/.m2/repository/com/aliyun/aliyun-java-sdk-core/3.4.0/aliyun-java-sdk-core-3.4.0.jar:/Users/huyi/.m2/repository/com/aliyun/aliyun-java-sdk-ram/3.0.0/aliyun-java-sdk-ram-3.0.0.jar:/Users/huyi/.m2/repository/com/aliyun/aliyun-java-sdk-sts/3.0.0/aliyun-java-sdk-sts-3.0.0.jar:/Users/huyi/.m2/repository/com/aliyun/aliyun-java-sdk-ecs/4.2.0/aliyun-java-sdk-ecs-4.2.0.jar:/Users/huyi/.m2/repository/com/aliyun/aliyun-java-sdk-kms/2.7.0/aliyun-java-sdk-kms-2.7.0.jar:/Users/huyi/.m2/repository/com/google/code/gson/gson/2.8.8/gson-2.8.8.jar:/Users/huyi/.m2/repository/cn/hutool/hutool-all/5.7.15/hutool-all-5.7.15.jar com.hy.csdn.tools.NetworkInterfaceUtil
getName获得网络设备现实名称=utun1
getDisplayName获得网络设备现实名称=utun1
getIndex获得网络接口的索引=12
isUp是否已经开启并运行=true
isLoopback是否为回调接口=false
getMTU获得最大传输单元=2000
获取此IP地址的完全限定域名=fe80:0:0:0:63a3:85eb:e7ec:770d%utun1
获取此IP地址的主机名=fe80:0:0:0:63a3:85eb:e7ec:770d%utun1
获取此IP地址的字符串=fe80:0:0:0:63a3:85eb:e7ec:770d%utun1
getAddress返回此InetAddress对象的原始IP地址=-2 -128 0 0 0 0 0 0 99 -93 -123 -21 -25 -20 119 13
getName获得网络设备现实名称=utun0
getDisplayName获得网络设备现实名称=utun0
getIndex获得网络接口的索引=11
isUp是否已经开启并运行=true
isLoopback是否为回调接口=false
getMTU获得最大传输单元=1380
获取此IP地址的完全限定域名=fe80:0:0:0:3b2:454d:40f6:fa91%utun0
获取此IP地址的主机名=fe80:0:0:0:3b2:454d:40f6:fa91%utun0
获取此IP地址的字符串=fe80:0:0:0:3b2:454d:40f6:fa91%utun0
getAddress返回此InetAddress对象的原始IP地址=-2 -128 0 0 0 0 0 0 3 -78 69 77 64 -10 -6 -111
getName获得网络设备现实名称=llw0
getDisplayName获得网络设备现实名称=llw0
getIndex获得网络接口的索引=10
isUp是否已经开启并运行=true
isLoopback是否为回调接口=false
getMTU获得最大传输单元=1500
获取此IP地址的完全限定域名=fe80:0:0:0:1c5b:adff:fec2:41ef%llw0
获取此IP地址的主机名=fe80:0:0:0:1c5b:adff:fec2:41ef%llw0
获取此IP地址的字符串=fe80:0:0:0:1c5b:adff:fec2:41ef%llw0
getAddress返回此InetAddress对象的原始IP地址=-2 -128 0 0 0 0 0 0 28 91 -83 -1 -2 -62 65 -17
getName获得网络设备现实名称=awdl0
getDisplayName获得网络设备现实名称=awdl0
getIndex获得网络接口的索引=9
isUp是否已经开启并运行=true
isLoopback是否为回调接口=false
getMTU获得最大传输单元=1484
获取此IP地址的完全限定域名=fe80:0:0:0:1c5b:adff:fec2:41ef%awdl0
获取此IP地址的主机名=fe80:0:0:0:1c5b:adff:fec2:41ef%awdl0
获取此IP地址的字符串=fe80:0:0:0:1c5b:adff:fec2:41ef%awdl0
getAddress返回此InetAddress对象的原始IP地址=-2 -128 0 0 0 0 0 0 28 91 -83 -1 -2 -62 65 -17
getName获得网络设备现实名称=en0
getDisplayName获得网络设备现实名称=en0
getIndex获得网络接口的索引=4
isUp是否已经开启并运行=true
isLoopback是否为回调接口=false
getMTU获得最大传输单元=1500
获取此IP地址的完全限定域名=fe80:0:0:0:df:d7c9:cd1:81e3%en0
获取此IP地址的主机名=fe80:0:0:0:df:d7c9:cd1:81e3%en0
获取此IP地址的字符串=fe80:0:0:0:df:d7c9:cd1:81e3%en0
getAddress返回此InetAddress对象的原始IP地址=-2 -128 0 0 0 0 0 0 0 -33 -41 -55 12 -47 -127 -29
获取此IP地址的完全限定域名=192.168.3.107
获取此IP地址的主机名=192.168.3.107
获取此IP地址的字符串=192.168.3.107
getAddress返回此InetAddress对象的原始IP地址=-64 -88 3 107
getName获得网络设备现实名称=lo0
getDisplayName获得网络设备现实名称=lo0
getIndex获得网络接口的索引=1
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!**
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!