I tried my best and commented the code for you. In case of difficulties, ping me...
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
*
* @author Sam
*/
public class PortChecker {
public static void main(final String... args)
throws InterruptedException, ExecutionException,
FileNotFoundException, IOException {
final ExecutorService es
= Executors.newFixedThreadPool(20);
BufferedReader br = new
BufferedReader(new FileReader("fports"));
final String ip =
br.readLine(); //read ip or hostnaem
final int timeout =
200;
System.out.println(ip);
String port;
final
List<Integer> ports = new ArrayList<>();
while ((port =
br.readLine()) != null) {
ports.add(Integer.parseInt(port)); //read and addd ports
System.out.println(port); //print port
}
final
List<Future<Boolean>> futures = new
ArrayList<>();
ports.stream().forEach((p) -> {
futures.add(portIsOpen(es, ip, p, timeout)); //try for each saved
ports
});
es.shutdown();
System.out.println("\n\n\n");
System.out.println(ip);
PrintWriter pw = new
PrintWriter("fports_results");
for (int i = 0; i <
ports.size(); i++) {
pw.println(ports.get(i) + "\t" + (futures.get(i).get() ? "open" :
"close")); //print port and status as open/clsoe
}
pw.flush();
pw.close();
}
public static Future<Boolean>
portIsOpen(final ExecutorService executorService, final String ip,
final int port, final int timeout) { //to parallelizeand reduce
time
return
executorService.submit(() -> {
try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress(ip, port), timeout);
return true; //if port open,return true
} catch (Exception ex) {
return false; //if closed
}
});
}
}
Java Language Create file fports with the first line as a hostname that needs to be...
Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this file, include your assignment documentation code block. After the documentation block, you will need several import statements. import java.util.Scanner; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; Next, declare the Lab12 class and define the main function. public class Lab12 { public static void main (String [] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare...
This isa Java program
Create file, file 1, with the following values: 3 4 35 20 -43 17 -10 6 7 -2 13 1 2 3 Write a program in Java to do the following: Open "file 1" and read the first two values, rand c, which are supposed to indicate the dimensions of the two-dimensional array whose values are given in the file after the values of r and c. Create a two-dimensional array of size r times c....
1. Create a file that contains 20 integers or download the attached file twenty-integers.txt twenty-integers.txt reads: 12 20 13 45 67 90 100 34 56 89 33 44 66 77 88 99 20 69 45 20 Create a program that: 2. Declares a c-style string array that will store a filename. 3. Prompts the user to enter a filename. Store the file name declared in the c-string. 4. Opens the file. Write code to check the file state. If the...
Using network sockets, write a C program called client that receives three command-line arguments in the form: client host port file and sends a request to a web server. The command-line arguments are hostRepresents the web server to connect to port Represents the port number where a request is sent. Normally an HTTP request is sent over port 80, but this format allows for custom ports file Represents the file requested from the web server Your program should create a...
This is JAVA language Create a .java class called MoreArrayFun.java with only a main method. This program will use the ArrayManager class. The final version of the program is described below, but initially use it to test your ArrayManager class as you write it. Complete the ArrayManager class as specified below: The class will have exactly two instance variables: An array of integers A count of the number of elements currently in the array The class will have...
PYTHON PROGRAMMING LANGUAGE Task 5 Open a csv file for writing create 3 rows that store username, first name, last name and age data (four columns) write the data to the csv file under the correct column Task 6 Open the file in task 5) and read its contents Output the content in a tabular format of columns and values
Write a java program to create a student file which includes first name, last name, and GPA. Write another Java program to open the students file. Display the students list and calculate the average GPA of the class.
java Part 1 Create a NetBeans project that asks for a file name. The file should contain an unknown quantity of double numeric values with each number on its own line. There should be no empty lines. Open the file and read the numbers. Print the sum, average, and the count of the numbers. Be sure to label the outputs very clearly. Read the file values as Strings and use Double.parseDouble() to convert them. Part 2 Create a NetBeans project...
Write a Java method that will take an array of integers of size n and shift right by m places, where n > m. You should read your inputs from a file and write your outputs to another file. Create at least 3 test cases and report their output. I've created a program to read and write to separate files but i don't know how to store the numbers from the input file into an array and then store the...
in java please Create a command line program Add an array that stores 20 integers Fill the array with random integers between 1 and 1000. Display the values in the array to stdout (the screen). Include a message explaining what is being displayed. Save the values in the array to a text file. Read the values stored in the text file to stdout (the screen). Include a message explaining what is being displayed.