我可以使用我的 java 程序打开一个关闭的端口吗?
Can I open a closed port using my java program?
我试过这个来听打开端口..
public class PortCheck {
public static void main(String[] args) {
try {
Socket socket = new Socket("localhost",4500);
System.out.println("port open");
} catch (IOException e) {
System.out.println("not open");
}
}
}
但是我想从我的 java program.Is 打开一个关闭的端口,有什么办法吗?
Socket
is a client socket for connecting to a server. To open a listening socket to accept clients, you need to use ServerSocket
相反,如果端口尚未打开,它将打开一个端口,如果端口已被使用,它将失败。
public class PortCheck {
public static void main(String[] args) {
try {
ServerSocket socket = new ServerSocket(4500, 0, InetAddress.getLocalHost());
System.out.println("port available");
} catch (IOException e) {
System.out.println("port not available");
}
}
}
我试过这个来听打开端口..
public class PortCheck {
public static void main(String[] args) {
try {
Socket socket = new Socket("localhost",4500);
System.out.println("port open");
} catch (IOException e) {
System.out.println("not open");
}
}
}
但是我想从我的 java program.Is 打开一个关闭的端口,有什么办法吗?
Socket
is a client socket for connecting to a server. To open a listening socket to accept clients, you need to use ServerSocket
相反,如果端口尚未打开,它将打开一个端口,如果端口已被使用,它将失败。
public class PortCheck {
public static void main(String[] args) {
try {
ServerSocket socket = new ServerSocket(4500, 0, InetAddress.getLocalHost());
System.out.println("port available");
} catch (IOException e) {
System.out.println("port not available");
}
}
}