Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python check if port in use

import socket

HOST = "localhost"
PORT = 443

# Creates a new socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Try to connect to the given host and port
if sock.connect_ex((HOST, PORT)) == 0:
print("Port " + str(PORT) + " is open") # Connected successfully
else:
print("Port " + str(PORT) + " is closed") # Failed to connect because port is in use (or bad host)

# Close the connection
sock.close()
Comment

PREVIOUS NEXT
Code Example
Python :: convert text file into list 
Python :: numpy from csv 
Python :: importying listviewin django 
Python :: python shuffle list 
Python :: spacy stopwords 
Python :: python pendas shut off FutureWarning 
Python :: is python easier than javascript 
Python :: pygame fullscreen 
Python :: update anaconda 
Python :: python turtle square 
Python :: matplotlib grid in background 
Python :: edit json file python 
Python :: RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() 
Python :: python check ram usage 
Python :: how to make turtle invisible python 
Python :: converting string array to int array python 
Python :: special characters list in python 
Python :: plot categorical data matplotlib 
Python :: how to get all links from a website python beautifulsoup 
Python :: series datetime64 seconds to 0 
Python :: numpy random float array between 0 and 1 
Python :: brownie to wei 
Python :: django foreign key field on delete do nothing 
Python :: dataframe to txt 
Python :: pandas shift one column 
Python :: python day from date 
Python :: python display object attributes 
Python :: simplify fractions python 
Python :: python program that takes command line arguments as input and print the number of arguments 
Python :: how to trim mp4 with moviepy 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =