Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Identify the IP addresses of the other people in the coffee shop. (Easier versio

ID: 3722708 • Letter: I

Question

Identify the IP addresses of the other people in the coffee shop. (Easier version of the exercise: Your source IP is 10.3.0.18). You know that all the other machines on the coffee shop's local area network have the same subnet as you; in other words, they share the first three bytes in their IP address as you. Create a new function called findOtherIPs() that finds the other IPs of the people in the coffee shop. Need a hint? Remember that the other IPs have the same subnet as you. In other words their IPs start with 10.3.0. Your function should return the collection of all the IPs of the people in the coffee shop.

from scapy.all import *
import sys

def parsePCAP(pkts):
for pkt in pkts:
    print "Source IP: " + pkt[IP].src  
    print "Destination IP: " + pkt[IP].dst  
    print "Source port: " + str(pkt[TCP].sport)  
    print "Destinations port: " + str(pkt[TCP].dport)  
    print "Packet Payload: " + str(pkt[TCP].payload)  

if __name__ == "__main__":
if len(sys.argv) < 2:
    print "usage: python lab3.py [pcap]"
    sys.exit()  
pcap= rdpcap(sys.argv[1])
pcap = [pkt for pkt in pcap if TCP in pkt]
parsePCAP(pcap)

Explanation / Answer

Soltion for the problem is :

def findOtherIPs ( pkts ):
unique = []
for pkt in pkts :
if " 10.3.0 " in pkt [IP ]. src :
if pkt [IP ]. src not in unique :
unique . append (pkt [IP ]. src )
return unique

Another solution is:

def findOtherIPsv2 ( pkts ):
return list (set ([ pkt [IP ]. src for pkt in pkts if " 10.3.0 " in pkt [IP ]. src ]))