Ticker

6/recent/ticker-posts

Code Port Scanner In Python3

Hey guy's we are come back with another excited tutorial in which we learn how to code a port scanner in python. So excited let's get started.

What is Port Scanner

Port scanner is a tool which is used to scan ports of server or host and find out which ports are open or close. This is basically used for information gathering by pen-testers or ethical hackers. So let's code your first port scanner.

print("{0:-^33}".format("kinghacker0"))

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

host = input("Enter Your Ip or Domain : ")
port = int(input("Enter Your Port : "))

def Scanner(port) :
      if s.connect_ex((host, port)):
           print("The Port is closed")
      else:
           print("The Port is Open!")

Scanner(port)

So let describe what we coded !

  1. Added our title print("{o:-^33}".format("name"))
  2. Create socket object import socket
  3. Setup parameters of socket AF_INET and SOCK_STREAM
  4. Set target host and port
  5. Set def function for if and else
That's all.

If you still have any question or suggestion then feel free to comment below and make sure to subscribe our YouTube channel for video tutorials. Thanks for visit have a nice day.

More Recommended Posts..