I guess you have to find the IP address using something like ip -f inet addr show ppp0
, extracting it with grep, awk or sed. Note that my case is different: my 3G device is a router so always presents a local ip address. YMMV.
Note also you will have to address the security issue discussed here.