Example usage for java.net InetAddress getByName

List of usage examples for java.net InetAddress getByName

Introduction

In this page you can find the example usage for java.net InetAddress getByName.

Prototype

public static InetAddress getByName(String host) throws UnknownHostException 

Source Link

Document

Determines the IP address of a host, given the host's name.

Usage

From source file:co.cask.cdap.security.server.ExternalLDAPAuthenticationServerTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.Security.AUTH_SERVER_BIND_ADDRESS, "127.0.0.1");
    cConf.set(Constants.Security.SSL.EXTERNAL_ENABLED, "false");
    cConf.set(Constants.Security.AUTH_SERVER_BIND_PORT, "0");

    configuration = cConf;//from  w  w w.  ja va2  s  . c  om
    sConfiguration = SConfiguration.create();

    ldapListenerConfig = InMemoryListenerConfig.createLDAPConfig("LDAP", InetAddress.getByName("127.0.0.1"),
            ldapPort, null);
    testServer = new ExternalLDAPAuthenticationServerTest();
    testServer.setup();
}

From source file:examples.daytime.java

public static final void daytimeUDP(String host) throws IOException {
    DaytimeUDPClient client = new DaytimeUDPClient();

    // We want to timeout if a response takes longer than 60 seconds
    client.setDefaultTimeout(60000);/*from   ww w.  j av  a  2  s  . c o  m*/
    client.open();
    System.out.println(client.getTime(InetAddress.getByName(host)).trim());
    client.close();
}

From source file:com.savoycraft.util.TimeUtil.java

/**
 * Queries a NIST time server to get a difference between its time and the
 * local system time./*from   www  .  j  a v a2 s.c o  m*/
 */
public static void calibrate() {
    if (System.currentTimeMillis() < lastTimeRequest + 5000 || calibrated) {
        return;
    }

    NTPUDPClient timeClient = new NTPUDPClient();
    InetAddress inetAddress = null;
    try {
        inetAddress = InetAddress.getByName(TIME_SERVER);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    }
    TimeInfo timeInfo = null;
    try {
        timeInfo = timeClient.getTime(inetAddress);
    } catch (IOException e) {
        System.err.println("SavoyCraft could not contact time.nist.gov.");
        e.printStackTrace();
        return;
    }
    long returnTime = timeInfo.getReturnTime();
    calibration = System.currentTimeMillis() - returnTime;
    System.out.println(calibration);
    // Date time = new Date(returnTime);
    // System.out.println("Time from " + TIME_SERVER + ": " + time);

    lastTimeRequest = System.currentTimeMillis();

    calibrated = true;
}

From source file:com.wso2telco.gsma.authenticators.IPRangeChecker.java

/**
 * Checks if is valid range./*from   w  w w  .j a v  a2  s  .co  m*/
 *
 * @param ipStart   the ip start
 * @param ipEnd     the ip end
 * @param ipToCheck the ip to check
 * @return true, if is valid range
 */
public static boolean isValidRange(String ipStart, String ipEnd, String ipToCheck) {
    try {
        long ipLo = ipToLong(InetAddress.getByName(ipStart));
        long ipHi = ipToLong(InetAddress.getByName(ipEnd));
        long ipToTest = ipToLong(InetAddress.getByName(ipToCheck));
        return (ipToTest >= ipLo && ipToTest <= ipHi);
    } catch (UnknownHostException e) {
        log.error("Error ", e);
        return false;
    }
}

From source file:ch.epfl.eagle.daemon.util.Network.java

/**
 * Return the IP address of this machine, as determined from the hostname
 * specified in configuration or from querying the machine.
 *///from ww  w.  j av a  2s . c  o m
public static String getIPAddress(Configuration conf) {
    String hostname = getHostName(conf);
    try {
        return InetAddress.getByName(hostname).getHostAddress();
    } catch (UnknownHostException e) {
        return "IP UNKNOWN";
    }
}

From source file:de.idos.updates.install.FtpInstallerTest.java

@Before
public void setUp() throws Exception {
    InetAddress address = InetAddress.getByName("www.topby.by");
    ftpInstaller = new FtpFileInstaller(report, address, installation, DEFAULT_LOGIN, DEFAULT_WORKING_DIR);
}

From source file:de.idos.updates.repository.FtpRepository.java

public FtpRepository(String address) {
    try {/*from  w  ww . j  a  va  2s.c om*/
        this.inetAddress = InetAddress.getByName(address);
    } catch (UnknownHostException ex) {
        throw new IllegalArgumentException("Please specify a valid inet address for your FTP repository", ex);
    }
}

From source file:Main.java

public InputStream getWWWPageStream(String host, String file) throws IOException, UnknownHostException {

    InetAddress webServer = InetAddress.getByName(host);

    Socket httpPipe = new Socket(webServer, 80);
    if (httpPipe == null) {
        System.out.println("Socket to Web server creation failed.");
        return null;
    }/*from   w  ww . j  a va2 s .co m*/

    InputStream inn = httpPipe.getInputStream(); // get raw streams
    OutputStream outt = httpPipe.getOutputStream();

    DataInputStream in = new DataInputStream(inn); // turn into higher-level ones
    PrintStream out = new PrintStream(outt);

    if (inn == null || outt == null) {
        System.out.println("Failed to open streams to socket.");
        return null;
    }
    out.println("GET " + file + " HTTP/1.0\n");

    String response;
    while ((response = in.readUTF()).length() > 0) {
        System.out.println(response);
    }

    return in;
}

From source file:examples.rdate.java

public static final void timeUDP(String host) throws IOException {
    TimeUDPClient client = new TimeUDPClient();

    // We want to timeout if a response takes longer than 60 seconds
    client.setDefaultTimeout(60000);// w  ww.  jav a2  s  .c om
    client.open();
    System.out.println(client.getDate(InetAddress.getByName(host)).toString());
    client.close();
}

From source file:com.github.cc007.sleepypoweron.DefaultController.java

@RequestMapping(value = "/sleepy/poweron/{mac}", method = RequestMethod.GET)
public @ResponseBody Result powerOn(@PathVariable String mac) {
    Result r = new Result();
    InetAddress broadcast;/*from   w ww. ja  va  2  s  . c om*/
    try {
        broadcast = InetAddress.getByName("255.255.255.255");
        if (broadcast != null) {
            WakeOnLan.wake(broadcast, mac);
            r.result = 1;
        } else {
            r.result = 0;
        }
    } catch (UnknownHostException ex) {
        Logger.getLogger(DefaultController.class.getName()).log(Level.SEVERE, null, ex);
        r.result = 0;
    }

    return r;
}