Reputation: 21979
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?
Upvotes: 2
Views: 5298
Reputation: 239011
pppd
automatically calls a script in /etc/ppp/ip-up
when a link is brought up. In this script, $4
is the local IP address of the PPP link. (On some distributions, /etc/ppp/ip-up
is set to call the scripts in /etc/ppp/ip-up.d
, with $PPP_LOCAL
set to the IP address, so you can place your script there).
This way, you won't have to manually call the script - just bring up the PPP link and it'll be run automatically. There's a corresponding /etc/ppp/ip-down
you can use to undo your route when the link goes down.
Upvotes: 2
Reputation: 60110
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.
Upvotes: 4