Skip to content

Instantly share code, notes, and snippets.

@lasteminista
Created May 8, 2022 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lasteminista/9ecf647789f42339cd38766957717f21 to your computer and use it in GitHub Desktop.
Save lasteminista/9ecf647789f42339cd38766957717f21 to your computer and use it in GitHub Desktop.
Port Scanner Code Snippet 1
import socket
target = '127.0.0.1'
port = 80
def scan_port(target, port):
print(f'Scan Target > {target}')
# Create a socket object
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
# Test connection
test = s.connect_ex((target, port))
if test == 0:
print(f'Port {port} is [open]')
if __name__ == '__main__':
scan_port(target, port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment