Java示例从IP地址查找主机名 Java示例将主机名更改为其特定IP地址 Java示例确定本地IP地址 Java示例从IP地址查找主机名 import java.net.InetAddress; import java.net.UnknownHostException; public class NewClass1 { public static void main(String[] args) { InetAddress ip; String hostname; try { ip = InetAddress.getLocalHost(); hostname = ip.getHostName(); System.out.println("Your current IP address : " + ip); System.out.println("Your current Hostname : " + hostname); } catch (UnknownHostException e) { e.printStackTrace(); } } } Java示例将主机名更改为其特定IP地址 Java示例确定本地IP地址