[(really) OT] find IP address of a pppd

Paul Fenwick pjf at perltraining.com.au
Wed Oct 15 17:21:56 BST 2008


G'day Dirk / London.pm,

Dirk Koopman wrote:

> I want to be able to do this from within the program controlling the
> pppds, preferably without calling any helper programs (eg ifconfig or
> lsof) or doing any if-up/if-down magic from within pppd. I am presuming
> that this involves poking around inside /proc and/or /sys.

If I read this correctly, then if you *are* happy to use if-up/if-down
magic, you can put scripts in /etc/network/if-up.d/ and
/etc/network/if-down.d/ .  When an interface goes up or down, your script
will be called.

When if(up|down) calls your script, it will set the IFACE environment
variable to the interface that has changed state.  You can examine that
variable, and if it's a ppp interface, you can then ask for the IP address.

Personally, I'd use /sbin/ifconfig and a regexp to ask for the interface IP
address once I know it's up.  If you want to do things the hard way,
apparently it can be done with ioctl calls.

Note that the if-(up|down).d/ scripts should get called in order.  If you
absolutely have to know as soon as possible that the interface is up, make
sure yours comes asciibetically first.

I don't know if a race condition exists where your script can be called
before the interface is fully up and has negotiatied an IP address.  AFAIK,
the scripts are only called when the interface is fully up or fully down.
(There are if-pre-* directories if you need to get in before they go up/down).

Cheerio,

	Paul

-- 
Paul Fenwick <pjf at perltraining.com.au> | http://perltraining.com.au/
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681


More information about the london.pm mailing list