technical solution-Python Tutorial on Socket :How to Check TCP Port Status of remote Machine | Library Tutorial unix command tricks from Techmirrors

technical solution-Python Tutorial on Socket :How to Check TCP Port Status of remote Machine | Library Tutorial unix command tricks from Techmirrors



This video demonstrates how to check tcp port status of remote machine using Python Socket library.
How to scan tcp port using python
How to check reachability of a host
Socket library and address families explained
Socket library tutorial
How to use function in python
Sample Script added below
#############
import socket

socket.setdefaulttimeout(.5)
print(‘n’+’#’*50+’nStarted Executing the script’+ ‘n’+’#’*50 )
def port_check(ip,port):

DEVICE_SOCKET = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result_of_check = DEVICE_SOCKET.connect_ex((ip,port))

if result_of_check == 0:
print(str(ip)+” is Listening on Port “+ str(port))
DEVICE_SOCKET.close()
else:
print(str(ip)+” is not Listening on Port “+ str(port))
DEVICE_SOCKET.close()

port_check(‘192.168.0.1’,80)
port_check(‘192.168.11.10’,81)
port_check(‘192.168.0.10’,443)

print(‘n’+’#’*50+’nFinished Executing the script’+ ‘n’+’#’*50 )
#############

SourceTechmirrors