# -*- coding: utf-8 -*-
"""
Created on Wed Jun 26 21:48:50 2013

@author: haydz
"""

#! /usr/bin/env python

import sys
import time
from threading import Thread






print " Enter an IP address"
ipaddress= raw_input()
##
#print "Enter a port"
#porta= int(raw_input())
#
#
#print "Enter a 2nd port"
#portb = int(raw_input())



print " enter the port to start the range"
prangeStart = int(raw_input())

print "Enter the port to finish the Range"
prangeStop = int(raw_input()) + 1
print prangeStop

portRange = range(prangeStart, prangeStop)

#print " this is the Range of ports that will be scanned"
#for i in portRange:
#    print i
#    
chunk = int(round(len(portRange)/10.0))
#print chunk   

chunkfinal = [portRange[i:i+chunk] for i in range(0,len(portRange),chunk)]
#print chunkfinal



#----------------------------------------

def scapy_scan(ipaddress,port):
        from scapy.all import sr1,IP,TCP
        p= sr1(IP(dst=ipaddress)/TCP(dport=port,flags="S"))
        if p:
            print "--------------START -----------------------"
            p.show() 
            print "------------FINISH--------------------"

#
for x in chunkfinal:
#    for b in x:
    if __name__ == '__main__':
        try:
            Thread(target=scapy_scan, args=(ipaddress, x)).start()

           
                #Thread(target=scapy_scan, args=(ipaddress, portb)).start()
        except Exception, errtxt:
                print errtxt