Question

The instructions for my assignment are below; however I came across this code but when I...

The instructions for my assignment are below; however I came across this code but when I try to run it, I get nothing but either bugging issues or error in the python shell.

  1. Write a simple port scanner program using the built-in Socket module. Test your port scanner by targeting your own computer or you can reference https://www.hackthissite.org
  2. Test your code and document testing by taking screenshots.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE:

import socket

def port_scanner():
    # inclusive range 1 to 1024
    for port in range(1, 1024 + 1):
        socket_obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = socket_obj.connect_ex(("localhost", port))
        # checking for open port
        if result is None:
            print("Port ", port, "open")

        socket_obj.close()

port_scanner()


OUTPUT:

EXPLANATION:

The socket.connect_ex() returns None if a port is already in use, i.e., in the open state.
Hence we check whether it is None or not If None we print it.

Add a comment
Know the answer?
Add Answer to:
The instructions for my assignment are below; however I came across this code but when I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this assessment, you will create a simple Python port scanner using Python's built-in functions. You...

    For this assessment, you will create a simple Python port scanner using Python's built-in functions. You can use Python's default editor IDLE (Integrated Development and Learning Environment) or a Python editor of your choice to complete this assessment. Write a simple port scanner program using the built-in Socket module. Test your port scanner by targeting https://www.hackthissite.org Test your code and document testing by taking screenshots. Explain the approach taken to complete this assessment and the major decisions made. Here is...

  • I need help with an assignment, it invovles techniques such as web scraping to retrieve data...

    I need help with an assignment, it invovles techniques such as web scraping to retrieve data from the Internet using both Python built-in functions as well as third-party libraries. You can use Python's default editor IDLE (Integrated Development and Learning Environment) or a Python editor of your choice to complete this assignment. I need to do the  following: Write a program to test if a given page is found or not on the server. Write a Python program to download and...

  • Instructions: Each line of code is to be explained in a comment. I have provided an...

    Instructions: Each line of code is to be explained in a comment. I have provided an example for the first line of code. I want to know what the statement is doing, i.e. creating a function, using module, assigning a value and specifically what is the variable, function, parameters etc… Answer, What will be printed and What is the output in a comment The use of Python Library 2.7 may necessary to complete the assignment. 1. # port variable is...

  • Below is my code and the instructions for the code. I can't figure out what's wrong....

    Below is my code and the instructions for the code. I can't figure out what's wrong. Please help. Tasks This lab has two parts: Writing a searching function for 1D arrays. Writing a simple class. Part 1 – Searching Continuing with arrays, we will now expect you to find information in an array and derive useful properties from the information stored in an array. Start Eclipse. Change the workspace directory location to something "safe". You may want to temporarily choose...

  • I have to modify a server program and chat program to work as the following instructions...

    I have to modify a server program and chat program to work as the following instructions but I am completely clueless as to where to start. I'd appreciate any help on how to atleast get started. This must be done in java. Diffie-Hellman Two parties use a key agreement protocol to generate identical secret keys for encryption without ever having to transmit the secret key. The protocol works by both parties agreeing on a set of values (a) and (q)....

  • this assingent is to  pseudocode, i have instructions and the example my teacher had given me for...

    this assingent is to  pseudocode, i have instructions and the example my teacher had given me for this, could i have some assistance, i need to do this in netbeans IDE and i need to use the scanner method as well and i need to pass both. Overview: This assignment will allow you to use pseudocode to implement the program to see the value in planning first, coding later. While coding is the glamorous part of the job, software development is...

  • SMTP Your task is to develop a simple mail client that sends email to any recipient....

    SMTP Your task is to develop a simple mail client that sends email to any recipient. Your client will need to connect to a mail server, dialogue with the mail server using the SMTP protocol, and send an email message to the mail server. Python provides a module, called smtplib, which has built in methods to send mail using SMTP protocol. However, we will not be using this module in this lab, because it hide the details of SMTP and...

  • Instructions This assignment has to be completed by each student individually. NO COLLABORATION I...

    I need help creating a class diagram for this please: I am not sure what more you want? it has 2 classes at least Connect4 and Connect4TextConsole. Instructions This assignment has to be completed by each student individually. NO COLLABORATION IS ALLOWED Submit YourASURitelD ProjectDeliverable2.zip compressed folder should contain the following files following This the 1. 2. Connect4.java 〔Game Logic Module) Connect4TextConsole.java (Console-based Ul to test the gamel 3. JavaDoc documentation files index.html and all other supporting files such as.cs5...

  • Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment...

    Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment is meant to introduce you to design and implementation of exceptions in an object-oriented language. It will also give you experience in testing an object-oriented support class. You will be designing and implementing a version of the game Nim. Specifically, you will design and implement a NimGame support class that stores all actual information about the state of the game, and detects and throws...

  • JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole...

    JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization {    /* *...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT