Dz Coder & Developer

[Python] scan ports and get the state and the city

Image

 

 

#!/usr/bin/python
import socket
import subprocess
import sys
import os
import urllib2
from datetime import datetime

def aaa() :
 if os.name == ‘nt’:
    os.system(‘cls’)
        os.system(‘color a’)
 else:
    os.system(‘clear’)
aaa()
print “””
[+]======================================================[+]
[+] CoDeD By SoUiLaHxXx_Dz
[+] Gr33T’z : All My Friends
[+]======================================================[+]
“””

remoteServer    = raw_input(“Enter a remote host to scan [ip]: “)
start    = input(“Enter a start port: “)
end    = input(“Enter a end port: “)
remoteServerIP  = socket.gethostbyname(remoteServer)

print “-” * 60
print “Please wait, scanning remote host”, remoteServerIP
print “-” * 60
 
t1 = datetime.now()

cc = urllib2.urlopen(“http://api.hostip.info/get_html.php?ip=”+remoteServer)
cc1 = cc.read()
print cc1+”\n”.strip()
try:
    for port in range(int(start),int(end)):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = sock.connect_ex((remoteServerIP, port))
        if result == 0:
            print “Port {}: \t Open”.format(port)
        sock.close()
 
except KeyboardInterrupt:
    print “You pressed Ctrl+C”
    sys.exit()
 
except socket.gaierror:
    print ‘Hostname could not be resolved. Exiting’
    sys.exit()
 
except socket.error:
    print “Couldn’t connect to server”
    sys.exit()
 
t2 = datetime.now()

total =  t2 – t1
print ‘\n’
print ‘Scanning Completed in: ‘, total
print ‘./SoUiLaHxXx_Dz ^^’
raw_input(“Press ny key to ExiT…”)

 

 

 

 

 

or : http://pastebin.com/LtDgU8eT

Enjoy..!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s