1 21 22 package com.izforge.izpack.util; 23 24 import java.net.InetAddress ; 25 import java.net.ServerSocket ; 26 27 import com.izforge.izpack.panels.ProcessingClient; 28 import com.izforge.izpack.panels.Validator; 29 30 38 public class HostAddressValidator implements Validator 39 { 40 41 public boolean validate(ProcessingClient client) 42 { 43 InetAddress inet = null; 44 String host = ""; 45 int port = 0; 46 boolean retValue = false; 47 48 try 49 { 50 host = client.getFieldContents(0); 51 port = Integer.parseInt(client.getFieldContents(1)); 52 } 53 catch (Exception e) 54 { 55 return false; 56 } 57 58 try 59 { 60 inet = InetAddress.getByName(host); 61 ServerSocket socket = new ServerSocket (port, 0, inet); 62 retValue = socket.getLocalPort() > 0; 63 socket.close(); 64 } 65 catch (Exception ex) 66 { 67 retValue = false; 68 } 69 return retValue; 70 } 71 72 } 73 | Popular Tags |