package io.renren.common.utils;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class PortUtils {
    /**
     * Description: 判断目标主机端口是否被占用
     * @param host 目标主机ip
     * @param port 端口
     * @return 占用返回true，空闲返回false
     */
    public static boolean isPortUsing(String host,int port) throws UnknownHostException {
        boolean flag=false;
        InetAddress Address=InetAddress.getByName(host);
        try {
            Socket socket=new Socket(Address,port);
            flag=true;
        } catch (IOException e) {

        }
        return flag;
    }
}
