ip info on ubuntu

C++
$ systemd-resolve --status | grep Current

Source

Also in C++: