The first step is to understand why you need the IP address. Juju models not just the machines/applications but also the network(s) connecting the applications. Juju has a concept of spaces - you can read more here: https://juju.is/docs/spaces - which allows an administrator to restrict which segment of the network specific intra-application or inter-application traffic is routed over.
This means to get an IP address, your charm needs to have a relation. The simplest use case, would be for setting up a cluster, so you want traffic between units of the same application. In which case you need two things:
First, you need a peer relation, which can be setup in metadata.yaml:
Then, from your config-changed or relation-changed event handlers you could access the associated address with this code: