package
com.includehelp;
import
java.net.InetAddress;
import
java.net.NetworkInterface;
/**
* Program to get System IP, name and MAC Address of windows system
*/
public
class
SystemInfo {
public
static
void
main(String[] args) {
System.out.println(
"Host Name : "
+getSystemName());
System.out.println(
"Host IP : "
+getIPAddress());
System.out.println(
"Host Address : "
+getMAC());
}
/**
* Method for get System Name
* @return Host name
*/
private
static
String getSystemName(){
try
{
InetAddress inetaddress=InetAddress.getLocalHost();
String name = inetaddress.getHostName();
return
name;
}
catch
(Exception E){
E.printStackTrace();
return
null
;
}
}
/**
* method to get Host IP
* @return Host IP Address
*/
private
static
String getIPAddress(){
try
{
InetAddress inetaddress=InetAddress.getLocalHost();
String ip = inetaddress.getHostAddress();
return
ip;
}
catch
(Exception E){
E.printStackTrace();
return
null
;
}
}
/**
* method to get Host Mac Address
* @return Mac Address
*/
private
static
String getMAC(){
try
{
InetAddress inetaddress=InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(inetaddress);
byte
[] macArray = network.getHardwareAddress();
StringBuilder str =
new
StringBuilder();
for
(
int
i =
0
; i < macArray.length; i++) {
str.append(String.format(
"%02X%s"
, macArray[i], (i < macArray.length -
1
) ?
"-"
:
""
));
}
String macAddress=str.toString();
return
macAddress;
}
catch
(Exception E){
E.printStackTrace();
return
null
;
}
}
}