What syscall or command could I use to find the remote peer IP of an active tunnel on a *nix system
When Connecting to a VPN either l2tp/openvpn ppp0 or tun/tap the user specify the remote IP or an app does this by default, doing ifconfig gives this info:
ppp0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1280
inet 10.10.1.2 --> 10.10.1.1 netmask 0xff000000
or
utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1500
inet 172.21.22.151 --> 172.21.22.151 netmask 0xfffffe00
But having root privileges what command / syscall could be used to find the remote/peer IP used by the tunnel.
Currently I am using ifconfig, netstat but need to do many checks and compare output, therefore wondering what syscalls I or set of commands I could use in order create a script/code to automate this process.
When all traffic is routed through the tunnel using this helps:
$ netstat -rn | grep -i 192.168.1.1
default 192.168.1.1 UGScI 22 0 en1
178.142.189.92 192.168.1.1 UGHS 4 3530 en1
192.168.1.1/32 link#4 UCS 2 0 en1
Assuming 192.168.1.1
is the current gateway I found that 178.142.189.92
is the peer IP.
But would like to know if is an easy way to basically find the Destination
of the default gateway
Any ideas?