Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkSocket.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

    socket.i = CkSocket::ckCreate()
    If socket.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Populate a JsonObject with information about the local network adapters, including IPv4 addresses,
    ;  IPv6 addresses, and MAC addresses.
    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkSocket::ckGetAdaptersAddresses(socket,json)
    If success = 0
        Debug CkSocket::ckLastErrorText(socket)
        CkSocket::ckDispose(socket)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    CkJsonObject::setCkEmitCompact(json, 0)
    jsonStr.s = CkJsonObject::ckEmit(json)
    Debug jsonStr
    ;  JSON parsing code for this result can be generated at Chilkat's online tool:
    ;  https://tools.chilkat.io/jsonParse


    CkSocket::ckDispose(socket)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure