Question

Description: You will be creating a program extractIP.py which will read from a file called wireShark.txt...

Description: You will be creating a program extractIP.py which will read from a file called wireShark.txt and extract all the ip addresses which can be of the format: 1,2 or 3 digits. 1, 2 or 3 digits.1, 2, or 3 digits. 1,2,3 digits Here are some examples of valid IPv4 addresses: 10.0.0.1, 12.123.123.123, 126.255.255.254, 191.255.255.254, 192.168.1.1, 239.255.255.255 And you will output them to another file called IPAddresses.txt , one per line, listing source and destination. Example: Source Destination 12.123.123.123 123.123.123.123 Requirements: You will read from a file called wireShark.txt which will be located in the same directory as your code You will write to a file called IPAddresses.txt which will be located in the same directory as your code All files will be opened and closed correctly. You will not use regex to parse the file. Instead, you will check the characters individually Your loops will be structured correctly. You will use one or more functions which will take a parameter or more, and return a value You will use lists You will use the split function You will write a function called CheckLine(currentLine) which will check if currentline is of the format: No. Time Source Destination Protocol Length Info Once you have identified this particular line, you will know that the following line has the IP addresses for source and destination in the second and third elements. 1 0.000000 192.168.1.180 239.255.255.250 SSDP 372 NOTIFY * HTTP/1.1 Your functions and main code will be in separate sections of your program. Your IP addresses will be formatted in IPv4 format, i.e. 1, 2 or 3 digits .1, 2 or 3 digits.1,2 or 3 digits. 1,2,3 digits It is ok to reuse the code you wrote for past homework including homework 4.

Homework Answers

Answer #1

wireShark.txt

id source destination length
1 12.13.13.11 12.15.17.199 34
2 12.1.132.132 121.15.17.199 32
3 12.13.133.132 121.1532.17.199 31
4 12.131.13.132 12.15.17.199 38
5 12.1345.134.132 12.15.17.199 349
6 12.13a.134.132 12.15.17.199 349

#source code:

def check_ip(ip):
   numbers=["0","1","2","3","4","5","6","7","8","9"]
   che=ip.split(".")
   check_digit=0
   check_count=0
   for i in range(len(che)):
       for j in range(len(che[i])):
           if che[i][j] not in numbers:
               check_digit=1
               break
   if(check_digit==0):
       for i in range(len(che)):
           if((len(che)==4) and (len(che[i])<4 and len(che[i])>0)):
               pass
           else:
               check_count=1
               break
   return check_count,check_digit
f=open("wireShark.txt","r")
data=[]
for line in f.readlines():
   data.append(line.replace("\n",""))
ip_list=[]
for i in range(1,len(data),1):
   list=data[i].split(" ")
   ip_list.append([list[1],list[2]])
for i in range(len(ip_list)):
   check1,check1d=check_ip(ip_list[i][0])
   check2,check2d=check_ip(ip_list[i][1])
   if(check1==0 and check2==0 and check1d==0 and check2d==0):
       f=open("ipaddress.txt","a+")
       f.write(ip_list[i][0]+" "+ip_list[i][1]+"\n")
f.close()
print("File created successfully")
  


  
  

#output:

#if you have any doubts comment below......

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In this assignment, you will analyze a log file from a web server to count the...
In this assignment, you will analyze a log file from a web server to count the number of hits made from each unique IP address. Step 1: Write the mapper, reducer, and driver code so that the final output of your program should be a file containing a list of IP addresses, and the number of hits from that address. The main idea is to examine the input data file to learn about the format of the input. Your mapper...
Write a Java Program, that opens the file "students.txt" The program must read the file line...
Write a Java Program, that opens the file "students.txt" The program must read the file line by line The program parses each line that it reads For example, for this line: 1:mohamed:ali:0504123456:cs102:cs202 The program must print    >ID = 1    >First Name = Mohamed   >Last Name = Ali   >Mobie = 0504123456   >Courses = cs102, cs202 In addition, it adds the mobile phone number into an ArrayList called studentPhoneList Print the content and the size of studentPhoneList Show your results and provide...
Linux Operation SECTION 2 – File and Directory Permissions: FILE PERMISSIONS: What is the command used...
Linux Operation SECTION 2 – File and Directory Permissions: FILE PERMISSIONS: What is the command used to find out which user account you are logged into?      . This command may come in handy in the following exercises. Ensure you are in your home directory of the student1 account. Use the echo command with output redirection to create a file called labfile4 and put the following text in this file: “This is the first line of labfile4”. Using the symbolic notation...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat (posted on Canvas)and store it into an array. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be determined. Your program should then prompt the user to enter another whole number between 2 and 20 (you may assume the user enters a valid value) and...
You are to write a C program that will read from a file, one or more...
You are to write a C program that will read from a file, one or more sets of x,y coordinates. Each set of coordinates is part of a Cartesian system. A Cartesian coordinate system is a system that specifies each point uniquely in a plane by a pair of numerical coordinates. Your program will determine which quadrant each set belong. - Quadrants are often numbered 1st - 4th and denoted by Roman numerals: I(+,+), II (−,+), III (−,−), and IV...
we will be taking data in as a file. you cannot use the data values in...
we will be taking data in as a file. you cannot use the data values in your source file but you must read in everything into variables and use it from there. First we need to include <fstream> at the top of our file. We will need to create an input file stream to work and ifstream. ifstream is a datatype. Create a variable with the datatype being ifstream. Variable is drfine by using the member accessor operator to call...
You must write a function that works like a small editor. It should open an existing...
You must write a function that works like a small editor. It should open an existing file (let us say this is File1.txt. This file must exist before the function is run), read it line by line. Then write it to another file (let us say this is File2.txt. This file need not exist since Python will create it). However, if a certain line exists in the first file, it should be replaced by another line supplied by you. You...
Write a Java class called CityDistances in a class file called CityDistances.java.    2. Your methods...
Write a Java class called CityDistances in a class file called CityDistances.java.    2. Your methods will make use of two text files. a. The first text file contains the names of cities. However, the first line of the file is a number specifying how many city names are contained within the file. For example, 5 Dallas Houston Austin Nacogdoches El Paso b. The second text file contains the distances between the cities in the file described above. This file...
USING MATLAB Write a program called QuadProg that determines the roots of a quadratic equation. Use...
USING MATLAB Write a program called QuadProg that determines the roots of a quadratic equation. Use functions to implement each action. Zip you directory of *.m files into a single file and turn this in on BBLearn under Class Activities. QuadProg write a function called getInputs to get a single input value. write a function called findDiscriminant write a function called findDenominator write a function called findRoot which will be used for both roots write a function called displayResults displayResults...
Create a program that generates a file of random numbers, and then prints them in neat...
Create a program that generates a file of random numbers, and then prints them in neat fashion to another file, and also saves to that file the average and standard deviation of those numbers. I) First, you would need to generate a file of random numbers that consists of N random numbers (100 < N < 1000). Each random digit should be a real number (type double) between 0 and 50. This file and its digits would now serve as...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT