Created
June 30, 2022 06:09
-
-
Save iyashjayesh/320a8207423e3bde9c4813d135c4973e to your computer and use it in GitHub Desktop.
Java Program to get Ip address and Hostname
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.net.*; | |
public class InetSampleCode { | |
public static void main(String[] args) { | |
try { | |
InetAddress id = InetAddress.getLocalHost(); | |
System.out.println("Host Name: " + id.getHostName()); | |
System.out.println("IP Address: " + id.getHostAddress()); | |
} catch (Exception e) { | |
System.out.println(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment