Network scanning ( Ethical Hacking ) using python
Here is an example of a simple Python program that can be used for ethical hacking:
python
import socket
def scan_port(target_host, target_port):
try:
# Create a TCP socket
socket_obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Set a 3-second timeout
socket.setdefaulttimeout(3)
# Connect to the target host
socket_obj.connect((target_host, target_port))
# Print an open port message
print(f"[+] Port {target_port} is open")
# Close the socket connection
socket_obj.close()
except socket.error:
# Print a closed port message
print(f"[-] Port {target_port} is closed")
def main():
# Get the target host and port from the user
target_host = input("Enter the target host: ")
target_port = int(input("Enter the target port: "))
# Call the scan_port function
scan_port(target_host, target_port)
if __name__ == "__main__":
main()
This program allows you to input a target host and port, and then it attempts to connect to that port on the target host using a TCP socket. If the connection is successful, it prints a message indicating that the port is open. If the connection fails or times out, it prints a message indicating that the port is closed.
Note that this example is a very basic demonstration of network scanning, which is one aspect of ethical hacking. Ethical hacking encompasses a wide range of techniques and tools, and it is important to have proper authorization and use these techniques responsibly and legally.
Comments
Post a Comment