Exemplo n.º 1
0
 private InetAddress getInetAddress(String ipaddr) {
   InetAddress inetaddr = null;
   StringTokenizer st = new StringTokenizer(ipaddr, ".");
   byte[] ipBytes = new byte[4];
   if (st.countTokens() == 4) {
     for (int i = 0; i < 4; i++) {
       ipBytes[i] = (byte) Integer.parseInt(st.nextToken());
     }
   } else {
     error("Incorrect IP address format: " + ipaddr, this);
     return null;
   }
   try {
     inetaddr = InetAddress.getByAddress(ipBytes);
   } catch (UnknownHostException e) {
     e.printStackTrace();
   }
   return inetaddr;
 }