快速测试指定IP和端口是否可以访问

时间:2020-12-30 15:20:08
package a.b.c;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class TestIp {
	public static void main(String[] args){
		Socket connect = new Socket();
		
		try {
			connect.connect(new InetSocketAddress("192.168.2.103", 3336),100);
			
			boolean res = connect.isConnected();
			System.out.println("" + res);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				connect.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}