87aCk_X

scan ports and get the state and the city

Oct 2nd, 2013
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1.    
  2.  
  3.     #!/usr/bin/python
  4.     import socket
  5.     import subprocess
  6.     import sys
  7.     import os
  8.     import urllib2
  9.     from datetime import datetime
  10.      
  11.     def aaa() :
  12.      if os.name == 'nt':
  13.             os.system('cls')
  14.             os.system('color a')
  15.      else:
  16.             os.system('clear')
  17.     aaa()
  18.     print """
  19.    [+]======================================================[+]
  20.    [+] CoDeD By Black_X
  21.    [+] Gr33T'z : All My Friends
  22.    [+]======================================================[+]
  23.    """
  24.      
  25.     remoteServer    = raw_input("Enter a remote host to scan [ip]: ")
  26.     start    = input("Enter a start port: ")
  27.     end    = input("Enter a end port: ")
  28.     remoteServerIP  = socket.gethostbyname(remoteServer)
  29.      
  30.     print "-" * 60
  31.     print "Please wait, scanning remote host", remoteServerIP
  32.     print "-" * 60
  33.      
  34.     t1 = datetime.now()
  35.      
  36.     cc = urllib2.urlopen("http://api.hostip.info/get_html.php?ip="+remoteServer)
  37.     cc1 = cc.read()
  38.     print cc1+"\n".strip()
  39.     try:
  40.         for port in range(int(start),int(end)):
  41.             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  42.             result = sock.connect_ex((remoteServerIP, port))
  43.             if result == 0:
  44.                 print "Port {}: \t Open".format(port)
  45.             sock.close()
  46.      
  47.     except KeyboardInterrupt:
  48.         print "You pressed Ctrl+C"
  49.         sys.exit()
  50.      
  51.     except socket.gaierror:
  52.         print 'Hostname could not be resolved. Exiting'
  53.         sys.exit()
  54.      
  55.     except socket.error:
  56.         print "Couldn't connect to server"
  57.         sys.exit()
  58.      
  59.     t2 = datetime.now()
  60.      
  61.     total =  t2 - t1
  62.     print '\n'
  63.     print 'Scanning Completed in: ', total
  64.     print './Black_X
  65.    raw_input("Press ny key to ExiT...")
Add Comment
Please, Sign In to add comment