Search code examples
linuxcommand-lineppp

How to get pppd inet address from shell command


I'm not sure whether to post it here or at ServerFault. Anyway, I'm trying to work around company's firewall to connect to some media sharing site using my phone's 3g network. I've come up with a simple ip route command which take pppd's inet address as it's parameter. But, I want to make it a little bit more automated by reading the inet address right from the script, not by passing it via command line parameter.

Here's the scenario, to make it more obvious:

  • The command invocation as of now: $jumpfirewall xxx.xxx.xxx.xxx

  • The command invocation I want: $jumpfirewall

Do you know some command or library that I can use to read it from command line?


Solution

  • Adapted from cyberciti:

    /sbin/ifconfig ppp0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

    The ifconfig ppp0 will get information for your primary PPP interface; the grep cuts it down to the line containing the IP address; the cut splits out everything after inet addr: up to bcast:, giving something like 1.2.3.4 Bcast:; and the awk call will print only the first (space-separated) field, leaving you with only the IP address.