

# Using the range function to specify ports (here it will scans all ports between ) Print "Please wait, scanning remote host", remoteServerIP # Print a nice banner with information on which host we are about to scan RemoteServerIP = socket.gethostbyname(remoteServer) RemoteServer = raw_input("Enter a remote host to scan: ") Save the file as: “portscanner.py” and exit the editor #!/usr/bin/env python Open up an text editor, copy & paste the code below. The first thing we must do is import the socket library and other libraries that we need. This small port scanner program will try to connect on every port you define for a particular host.
#FASTSCRIPTS PYTHON HOW TO#
How to make a simple port scanner program in Python. Socket.error Making a program using Python Sockets Get the fqdn (fully qualified domain name) Translate a host name to IPv4 address format, extended interface Translate a host name to IPv4 address format Socket Family (here Address Family version 4 or IPv4) Sock = socket.socket (socket.AF_INET, socket.SOCK_STREAM) Sock = socket.socket (socket_family, socket_type)

Socket functionsīefore we get started with our sample program, let’s see some of the socket functions we are going to use. The web browser’s that you use opens a socket and connects to the web server.Īny network communication goes through a socket.įor more reading about the socket module, please see the official documentation. The INET sockets, account for at least 99% of the sockets in use.
