Created
October 12, 2018 04:45
-
-
Save 0x9090/9270d60494764d3fad5e7c84b7d52656 to your computer and use it in GitHub Desktop.
Pure Python Port Scanner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import socket | |
import subprocess | |
import sys | |
from datetime import datetime | |
remoteServer = raw_input("Enter a remote host to scan: ") | |
remoteServerIP = socket.gethostbyname(remoteServer) | |
interface = raw_input("Enter a target interface: ") | |
try: | |
for port in range(1, 1025): | |
print "Scanning Port {}".format(port) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
socket.settimeout(1) | |
socket.setsockopt(socket.SOL_SOCKET, 25, interface) | |
result = sock.connect_ex((remoteServerIP, port)) | |
if result == 0: | |
print "Port {}: Open".format(port) | |
sock.close() | |
except KeyboardInterrupt: | |
print "Quitting" | |
sys.exit() | |
except socket.gaierror: | |
print "Hostname couldn't be resolved" | |
sys.exit() | |
except socket.error: | |
print "Couldn't connect to server" | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment