Skip to content

Instantly share code, notes, and snippets.

@0x9090
Created October 12, 2018 04:45
Show Gist options
  • Save 0x9090/9270d60494764d3fad5e7c84b7d52656 to your computer and use it in GitHub Desktop.
Save 0x9090/9270d60494764d3fad5e7c84b7d52656 to your computer and use it in GitHub Desktop.
Pure Python Port Scanner
#!/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