python socket get ip code example
Example 1: get IP address python
import socket
hostname = socket.gethostname()
IPAddr = socket.gethostbyname(hostname)
print("Your Computer Name is:" + hostname)
print("Your Computer IP Address is:" + IPAddr)
Example 2: get ip python
import socket
host = socket.getfqdn()
addr = socket.gethostbyname(host)
print(f"Your ip is {addr}")
Example 3: python socket get client ip address
import socket
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
Example 4: python socket get client ip address
Hostname: DESKTOP-A0PM5GD
IP Address: 192.168.43.15