IP config en java
Publicado por Camila (7 intervenciones) el 27/04/2017 23:53:28
Hola a todos
Necesito hacer el comando ipconfig en java
Ayuda!!
Necesito hacer el comando ipconfig en java
Ayuda!!
Valora esta pregunta
0
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package utilidades;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
/**
*
* @author wilso
*/
public class Utilidades {
public String Obtener_Host() throws UnknownHostException {
InetAddress datos = InetAddress.getLocalHost();
String Hostname = null;
try {
Hostname = datos.getHostName();
} catch (Exception e) {
}
return Hostname;
}
public String Obtener_ip() throws UnknownHostException {
InetAddress datos = InetAddress.getLocalHost();
String ip = null;
try {
ip = datos.getHostAddress();
} catch (Exception e) {
}
return ip;
}
public String Obtener_mac() throws UnknownHostException {
InetAddress datos = InetAddress.getLocalHost();
StringBuilder sb = new StringBuilder();
NetworkInterface result = null;
byte[] mac_obten = null;
String mac = null;
try {
result = NetworkInterface.getByInetAddress(datos);
mac_obten = result.getHardwareAddress();
for (int i = 0; i < mac_obten.length; i++) {
sb.append(String.format("%02X%s", mac_obten[i], (i < mac_obten.length - 1) ? "-" : ""));
}
mac = String.valueOf(sb);
} catch (Exception e) {
}
return mac;
}
}
Donse se implementa
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Utilidades x = new Utilidades();
try {
Hostname.setText(x.Obtener_ip());
IP.setText(x.Obtener_Host());
MAC.setText(x.Obtener_mac());
} catch (UnknownHostException ex) {
Logger.getLogger(Datos.class.getName()).log(Level.SEVERE, null, ex);
}
}