Here you can find the source of ping(String domain, int port)
public static final boolean ping(String domain, int port)
//package com.java2s; /*//from w w w .j a v a 2 s . c om * Copyright 1999-2004 Alibaba.com All right reserved. This software is the confidential and proprietary information of * Alibaba.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only * in accordance with the terms of the license agreement you entered into with Alibaba.com. */ import java.io.IOException; import java.net.Socket; import java.net.UnknownHostException; public class Main { public static final boolean ping(String domain, int port) { boolean result = false; Socket socket = null; try { socket = new Socket(domain, port); result = true; } catch (UnknownHostException e) { } catch (IOException e) { } finally { if (socket != null) { try { socket.close(); } catch (Exception ex) { } } } return result; } }