Answers for "python test socket without ip"

6

python socket get client ip address

## importing socket module
import socket
## getting the hostname by socket.gethostname() method
hostname = socket.gethostname()
## getting the IP address using socket.gethostbyname() method
ip_address = socket.gethostbyname(hostname)
## printing the hostname and ip_address
print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
Posted by: Guest on January-23-2021
1

python socket check if still connected

def is_still_connected(sock):
	try:
		sock.sendall(b"ping")
      	return True
	except:
    	return False
Posted by: Guest on December-07-2021

Python Answers by Framework

Browse Popular Code Answers by Language