How it works...

This recipe demonstrates how to scan open ports of a machine using Python's standard socket library. The scan_port() function takes three arguments: host, start_port, and end_port. Then, it scans the entire port range in three steps:

  1. Create a TCP socket using the socket() function.
  2. If the socket is created successfully, then resolve the IP address of the remote host using the gethostbyname() function.
  3. If the target host's IP address is found, try to connect to the IP using the connect() function. If that's successful, then it implies that the port is open. Now, close the port with the close() function and repeat the first step for the next port.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.203.96