views:

286

answers:

2

Hi guys,

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:

here's the command invocation as of now: $jumpfirewall xxx.xxx.xxx.xxx

here's the command invocation I want: $jumpfirewall

got the idea? good, now, do you know some command or library that I can use to read it from command line?

+1  A: 

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.

Tim
whoa, perfect! thank you!
silent
+1  A: 

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.

caf
I use script because I don't use the tunnel every-time I use my 3g network. Anyway, I vote up for the information
silent