Skip to content

Instantly share code, notes, and snippets.

@iyashjayesh
Created June 30, 2022 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iyashjayesh/320a8207423e3bde9c4813d135c4973e to your computer and use it in GitHub Desktop.
Save iyashjayesh/320a8207423e3bde9c4813d135c4973e to your computer and use it in GitHub Desktop.
Java Program to get Ip address and Hostname
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