Using SNMP to get WAN IP Address
Re: [Seems simple](but how? Get WAN IP address?)
I was looking for this too.
The command that worked for me was:
FreeBSD% bsnmpwalk -o quiet -s community@routerip 126.96.36.199.188.8.131.52.1.3.3 | tail -1
where 'community' = SNMP community (default is 'public')
routerip = the LAN address of the pfSense router
-o quiet = only show the value, used for scripting
tail -1 = only show the last value because the first value was the gateway
184.108.40.206.220.127.116.11.1.3 is the MIB for 'The IpAddress corresponding to the media-dependent 'physical' address.'
18.104.22.168.22.214.171.124.1.3.3 is the specific physical interface port on my router assigned to WAN. You can run the equivalent of
FreeBSD% bsnmpwalk -s public@routerip 126.96.36.199.188.8.131.52.1.3
to get the list of all interfaces with all associated IPv4 addresses.
ipNetToMediaNetAddress[1, 10.0.0.1] = 10.0.0.1 ... ipNetToMediaNetAddress[3, publicip] = publicip
This lists by interface ID, starting with 1. You would need to see which index number refers to your WAN by matching the IP address.
Additional considerations: the bsnmpwalk command is bsnmpget(1), built in to FreeBSD base. On other OSs, you may need to load snmpwalk
I considered using OID 184.108.40.206.220.127.116.11 , but the notes at https://oidref.com/18.104.22.168.22.214.171.124 say that it is deprecated in favor of something that is IPv4/6 comptible in the ipAddressTable OID. It had all IPs assigned to the router, so was too messy to use.
The above references what worked with the built in bsnmpd daemon. It may be worth checking if adding the net-snmp package (System > Package Manager > Available Packages > net-snmp) is more useful.