Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
38 views
in Information Technology by (141k points)
Can You Provide an Example of a Simple Port Scanner in Python?

Please log in or register to answer this question.

1 Answer

0 votes
by (141k points)

Sure, here's a basic example of a port scanner in Python using the socket library:

import socket

target = "example.com"
ports = [80, 443, 8080, 22]

def scan_port(host, port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(1)
    result = sock.connect_ex((host, port))
    sock.close()
    return result

for port in ports:
    if scan_port(target, port) == 0:
        print(f"Port {port} is open")
    else:
        print(f"Port {port} is closed")

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...