Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
In Java, you can use InetAddress.getLocalHost() to get the Ip Address of the current Server running the Java app and InetAddress.getHostName() to get Hostname of the current Server name. package com.crunchify.tutorials; import java.net.InetAddress; import java.net.UnknownHostException; /** * @author Crunchify.com */ public class CrunchifyGetIPHostname { 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(); } } }
31st Mar 2018, 7:16 AM
Baraa AB
Baraa AB - avatar