Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; even without the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- # All code posted on my Pastebin is designed for Linux (Debian-based)
- #
- # Description:
- # This python file takes one argument, the ip of the system
- # you want to scan. It then scans the tcp ports of your 'target'
- # to see if they are open.
- #
- # Example:
- # ./portscanner.py 127.0.0.1
- #
- # This example scans localhost to determine which ports are open.
- #
- import socket, sys, argparse
- from datetime import datetime
- def scan(target):
- try:
- for ports in range(1, 65535):
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
- result = s.connect_ex((target, ports))
- if result == 0:
- print("Port {}: \t Open".format(ports))
- s.close()
- except Exception, e:
- print e
- return 1
- def main():
- parser = argparse.ArgumentParser()
- parser.add_argument("target", help="The IP of the system you want to scan",type=str)
- a = parser.parse_args()
- scan(a.target)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement