Sample code for 30+ languages & platforms
Chilkat2-Python

Get Local Network Adapter Addresses

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetAdaptersAddresses, which populates a JsonObject with information about local network adapters, including IPv4 addresses, IPv6 addresses, and MAC addresses.

Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.

Background. This provides a portable way to enumerate the host's network interfaces and their addresses.

Chilkat Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

success = False

socket = chilkat2.Socket()

# Populate a JsonObject with information about the local network adapters, including IPv4 addresses,
# IPv6 addresses, and MAC addresses.
json = chilkat2.JsonObject()
success = socket.GetAdaptersAddresses(json)
if (success == False):
    print(socket.LastErrorText)
    sys.exit()

json.EmitCompact = False
jsonStr = json.Emit()
print(jsonStr)
# JSON parsing code for this result can be generated at Chilkat's online tool:
# https://tools.chilkat.io/jsonParse