That would do the trick in a Mac :
ping $(ifconfig en0 | awk '$1 == "inet" {print $2}')
That resolved to ping 192.168.1.2
in my machine.
Pro tip: $(...)
means run whatever is inside the parentheses in a subshell and return that as the value.