#!/usr/bin/env python
import socket
import sys
from datetime import datetime

# Ask for input
target = input("input ip address or remote hosts: ")
targetIP = socket.gethostbyname(target)


# header banner
print ("=" * 60)
print ("Please wait, scanning remote host", targetIP)
print ("=" * 60)

# Check the time when scan started
t1 = datetime.now()

# Using the range function to specify ports (here it will scans all ports between 1 and 1024)
# scan port range between 1 and 1024
try:
    for port in range(1,1024):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = sock.connect_ex((targetIP, port))
        if result == 0:
            print ("Port {}: 	 Open".format(port))
        sock.close()

# Checking the time again
t2 = datetime.now()

# Calculates the difference of time, to see how long it took to run the script
total = t2 - t1

# Printing the information to screen
print ('Scanning Completed in: ', total)
