Advertisement
SoUiLaHxXx_Dz

scan ports and get the state and the city

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