可以看下java8的InetAddress类,拿本机DNS也就是hostname
String localhostname = java.net.InetAddress.getLocalHost().getHostName();
至于subnet mask子网掩码
InetAddress localHost = Inet4Address.getLocalHost();
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);
for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
System.out.println(address.getNetworkPrefixLength());
}