#    you must have to install namp for windows from its official website, and then you are ready to go

import nmap                                   #    firstly do "pip install python-nmap" in your cmd
import sys
import socket

if len(sys.argv)<2:                                                               #  input must give url
    print("usage "+sys.argv[0]+" <URL>")                                          #  example-    python nmapscanner_modified.py xyz.com
    sys.exit(1)

target=str(sys.argv[1])

gethostby_=socket.gethostbyname(sys.argv[1])                          # we get the IP address of that entered website
gethostby_=str(gethostby_)                    

scan_v= nmap.PortScanner()                                           # instantiate a scan_v variable to nmap

print("\nScanning  "+target+"  for ports 1-1000   .....\n")

portscan=scan_v.scan(hosts=target,arguments='-T5 -Pn -p1-1000')      # in arguements, -Pn represents that we will assume that our host is awake

# portscan is of dictionary type

flag=0

if portscan['scan']:                                               # checking that is there any value assigned to portscan['scan']
    flag=1

if flag==1:
    print("\nTarget " , target, "is ", portscan['scan'][gethostby_]['status']['state'] , "\n")
    
    i=1
    while i<=1000:                                                                         # checking ports till 1000, (You can change it too)
        if i in portscan['scan'][gethostby_]['tcp']:
            print("port : ",i, " is ", portscan['scan'][gethostby_]['tcp'][i]['state'] ,"   Name :  ", portscan['scan'][gethostby_]['tcp'][i]['name'] ,"\n")
        i=i+1

else:
    print("Target is not up or No Port Open")