Advertisement
0x00sec_JINX

portscanner.py

Jun 27th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. #! /usr/bin/python
  2. #
  3. #   This program is free software: you can redistribute it and/or modify
  4. #   it under the terms of the GNU General Public License as published by
  5. #   the Free Software Foundation, either version 3 of the License, or
  6. #   (at your option) any later version.
  7. #
  8. #   This program is distributed in the hope that it will be useful,
  9. #   but WITHOUT ANY WARRANTY; even without the implied warranty of
  10. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #   GNU General Public License for more details.
  12. #
  13. #   You should have received a copy of the GNU General Public License
  14. #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15. #
  16. #   All code posted on my Pastebin is designed for Linux (Debian-based)
  17. #
  18. #   Description:
  19. #       This python file takes one argument, the ip of the system
  20. #       you want to scan. It then scans the tcp ports of your 'target'
  21. #       to see if they are open.
  22. #
  23. #       Example:
  24. #           ./portscanner.py 127.0.0.1
  25. #
  26. #       This example scans localhost to determine which ports are open.
  27. #      
  28.  
  29. import socket, sys, argparse
  30. from datetime import datetime
  31.  
  32. def scan(target):
  33.     try:
  34.  
  35.         for ports in range(1, 65535):
  36.             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  37.             s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
  38.             result = s.connect_ex((target, ports))
  39.             if result == 0:
  40.                 print("Port {}: \t Open".format(ports))
  41.             s.close()
  42.  
  43.     except Exception, e:
  44.         print e
  45.         return 1
  46.  
  47. def main():
  48.     parser = argparse.ArgumentParser()
  49.     parser.add_argument("target", help="The IP of the system you want to scan",type=str)
  50.     a = parser.parse_args()
  51.  
  52.     scan(a.target)
  53.  
  54. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement