create a function called \"read_ip_attack(file)\" receives a file object as a pa
ID: 3604264 • Letter: C
Question
create a function called "read_ip_attack(file)" receives a file object as a parameter (such as returned from open_file())and reads detected IP addresses corresponding to an attack to a network. This function returns a list of tuples, where each tuple (ip_int,ip_str) includes a 12-digit integer number representing the IP address, and a string of the IP address with .xxx appended to the end of the IP address. The IP addresses in the file are Class-C IP addresses which means that each one has three of the four numbers that make up an IP address (the fourth is left out of the data to ensure privacy by identifying subnetworks rather than individual machines—yes, we maintain the privacy of attackers!). To make a 12-digit integer out of three numbers, follow the steps explained in b) and add 000 to the right of the IP address, i.e. 102.1.2 should result in the tuple (102001002000, "102.1.2.xxx").
link for the file:http://www.cse.msu.edu/~cse231/Online/Projects/Project07/2017-09-27-attacks-small.txt or http://www.cse.msu.edu/~cse231/Online/Projects/Project07/2017-09-27-attacks.txt
Explanation / Answer
import java.io.File; importjava.io.IOException; public class RenameFile { public static void main(String[] args) { try // Here F is the object of the Existing file named with Includehelp which is to be renamed. // { File F=new File("f:/Includehelp.txt"); // Here T is the object of the renamed file of Includehelp which is Include.txt. // File T=new File ("f:/Include.txt"); // Rename the file Includehelp.txt into Include.txt. // F.renameTo(T); // Print the result if file renamed. // System.out.println("File Rename Successfully..."); } // If any error occurs while renaming the file. // catch(Exception e) { System.out.println(e); } } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.