xxxxxxxxxx
import socket
import uuid
def get_local_ip_mac():
# Get local IP
local_ip = socket.gethostbyname(socket.gethostname())
# Get MAC address
mac_address = ':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff)
for ele in range(0, 8 * 6, 8)][::-1])
return local_ip, mac_address
# Usage
ip, mac = get_local_ip_mac()
print("Local IP:", ip)
print("MAC address:", mac)
xxxxxxxxxx
import socket
def get_ip_address():
# Get the IP address of the computer
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
return ip_address
ip_address = get_ip_address()
print("IP Address:", ip_address)