#!/usr/bin/env python
#Import Library
import sys
import socket
import random
import scapy
from scapy.all import sr1,IP,ICMP,TCP
#script Name: Ops401challenge11
#Author: Bubacarr Darboe
#Date: 10/19/2020
#Description of purpose: packet sniffing
#Declaration of variable
host = "scranme.nmap.org"
port_range = [21, 22, 23]
src_port = 22
dst_port = 22
response = sr1(IP(dst=host)/TCP(sport=src_port,dport=dst_port,flags="S"),timeout=1,verbose=0)
###Function###
for dst_port in port_range:
    src_port = random.randint(1025,65534)

    if response is None:
        print("packet filtered")
    elif(response.haslayer(TCP)):
        if(response.getlayer(TCP).flags == 0x12): #port responding and open
            print("Port " + str(dst_port) + " is open")
        elif (response.getlayer(TCP).flag == 0x14):#port responding and closed
            print("Port " + str(dst_port) + " is closed")
        else:
            print("The port is filtered and dropped")#port is filtered and dropped silently
#Main
#End





