Ejemplo n.º 1
0
 /**
  * Convert a String IP in a InetAddress
  *
  * @param ip The String IP to convert
  * @return InetAddress - The converted InetAddress
  * @log UnknownHostException<br>
  *     <i>args: ip</i>
  */
 public static InetAddress getInetAddressFromIP(String ip) {
   try {
     return InetAddress.getByName(ip);
   } catch (UnknownHostException e) {
     Core.exception(e, "IP: " + ip);
     return null;
   }
 }
Ejemplo n.º 2
0
 public static String getIP() {
   if (IP.ip == null) {
     try {
       IP.ip = InetAddress.getLocalHost().toString().split("/")[1];
     } catch (UnknownHostException e) {
       Core.exception(e, "Cannot create ip", "IP");
     }
   }
   return IP.ip;
 }
Ejemplo n.º 3
0
 public static String getMAC() {
   if (IP.mac == null) {
     try {
       NetworkInterface network = NetworkInterface.getByInetAddress(Inet4Address.getLocalHost());
       byte[] mac = network.getHardwareAddress();
       String macaddress = "";
       for (int i = 0; i < mac.length; i++) {
         macaddress += String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
       }
       IP.mac = macaddress;
     } catch (SocketException | UnknownHostException e) {
       Core.exception(e, "Cannot create MAC", "IP");
     }
   }
   return IP.mac;
 }
Ejemplo n.º 4
0
 public static String getBroadcast() {
   if (IP.broadcast == null) {
     try {
       NetworkInterface network = NetworkInterface.getByInetAddress(Inet4Address.getLocalHost());
       InterfaceAddress address = null;
       for (InterfaceAddress add : network.getInterfaceAddresses()) {
         if (add != null) {
           address = add;
           break;
         }
       }
       IP.broadcast = address.getBroadcast().toString().split("/")[1];
       IP.mask = IP.parsePrefix(address.getNetworkPrefixLength());
     } catch (SocketException | UnknownHostException e) {
       Core.exception(e, "Cannot create Broadcast", "IP");
     }
   }
   return IP.broadcast;
 }