Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Computer Networking Interviews:Active DirectoryBasic NetworkingCable TesterCCNACCNA SecurityCCNPCDMA (Code division multiple access)Cisco Certified Internetwork Expert (CCIE)Client ServerClient-Server ComputingComputer NetworksCorbaData CommunicationsData Link LayerDigital RouterEthernet NetworkingFOC (Fiber Optic Route Checker)Java Network programmingLocal area network (LAN)MCSAMCSEMetropolitan area network (MAN)Network AdministratorNetwork ProgrammingNetwork/System AdministratorNetworks SecurityRoutersRoutingSWG and AWGSystem AdministrationSystem Support EngineerVoIPVPNWide area network (WAN)
Copyright © 2018. All Rights Reserved
Java Network programming Interview Question:
Explain Look for Local Ports?
Submitted by: AdministratorExample 11-1: Look for Local Ports
import java.net.*;
import java.io.*;
public class LocalPortScanner {
public static void main(String[] args) {
for (int port = 1; port <= 65535; port++)
{
try {
// the next line will fail and drop into the
catch block if there is already a server
running on the port//
ServerSocket server = new ServerSocket(port);
}
catch (IOException e) {
System.out.println("There is a server on port
" + port + ".");
} // end try
} // end for
}
}
Here's the output I got when running
LocalPortScanner on my NT workstation:
D:JAVAJNP2examples11>java LocalPortScanner
There is a server on port 135.
There is a server on port 1025.
There is a server on port 1026.
There is a server on port 1027.
There is a server on port 1028.
Submitted by: Administrator
import java.net.*;
import java.io.*;
public class LocalPortScanner {
public static void main(String[] args) {
for (int port = 1; port <= 65535; port++)
{
try {
// the next line will fail and drop into the
catch block if there is already a server
running on the port//
ServerSocket server = new ServerSocket(port);
}
catch (IOException e) {
System.out.println("There is a server on port
" + port + ".");
} // end try
} // end for
}
}
Here's the output I got when running
LocalPortScanner on my NT workstation:
D:JAVAJNP2examples11>java LocalPortScanner
There is a server on port 135.
There is a server on port 1025.
There is a server on port 1026.
There is a server on port 1027.
There is a server on port 1028.
Submitted by: Administrator
Copyright 2007-2025 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.