Getting the dynamic IP address of a dialup interface (ppp0)

I need to get the dynamic IP address of the ppp0 interface
(point-to-point) under Linux. I cannot do a reverse DNS
lookup since the associated name is dynamic too (something like
user-bla-bla-IP-.someisp.com), and I would prefer to avoid parsing
/sbin/ifconfig since
a) I don’t know how reliable it would be (and it’s ugly anyway)
b) I cannot get sample output to work on since I have no access to the
remote machine (I was planning on somebody installing my script that)

[Context: I’m binding a socket to that interface and sending the IP and
port info w/ UDP to another computer (server) behind a firewall that then
connects to the client. This is all required because of quite draconian
firewalling rules (my machine is behind THREE different firewalls,
ouch!)]

···


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

MSDOS didn’t get as bad as it is overnight – it took over ten years
of careful development.
– dmeggins@aix1.uottawa.ca

ifconfig should be virtually the same everywhere, so parsing should be
something like this: (works on FreeBSD)
http://segment7.net/ruby-code/snippits/get_ip.rb

···

Mauricio Fern?ndez (batsman.geo@yahoo.com) wrote:

I need to get the dynamic IP address of the ppp0 interface
(point-to-point) under Linux. I cannot do a reverse DNS
lookup since the associated name is dynamic too (something like
user-bla-bla-IP-.someisp.com), and I would prefer to avoid parsing
/sbin/ifconfig since
a) I don’t know how reliable it would be (and it’s ugly anyway)
b) I cannot get sample output to work on since I have no access to the
remote machine (I was planning on somebody installing my script that)

[Context: I’m binding a socket to that interface and sending the IP and
port info w/ UDP to another computer (server) behind a firewall that then
connects to the client. This is all required because of quite draconian
firewalling rules (my machine is behind THREE different firewalls,
ouch!)]


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

I cannot do a reverse DNS
lookup since the associated name is dynamic too

You could always register with dyndns.org(it’s free!) and have a
program like ddclient auto-refresh your DNS entry whenever you
connect to the net. That’s what I’m doing with my DSL connection
at home, and I can retrieve my remote IP as easy as:

require ‘socket’
ip_address = IPSocket.getaddress(“myhost.dyndns.org”)

Cheers,
Travis Whitton whitton@atlantic.net

Great! I have been reading ifconfig’s (net-tools’s) sources, and
apparently that info is taken from /proc/net/ (under Linux at least) and
using ioctl, and I guess parsing is more portable than trying ioctl
magic…

···

On Mon, Jan 27, 2003 at 07:37:38AM +0900, Eric Hodel wrote:

Mauricio Fern?ndez (batsman.geo@yahoo.com) wrote:

I need to get the dynamic IP address of the ppp0 interface
(point-to-point) under Linux. I cannot do a reverse DNS
lookup since the associated name is dynamic too (something like
user-bla-bla-IP-.someisp.com), and I would prefer to avoid parsing
/sbin/ifconfig since
a) I don’t know how reliable it would be (and it’s ugly anyway)
b) I cannot get sample output to work on since I have no access to the
remote machine (I was planning on somebody installing my script that)

[Context: I’m binding a socket to that interface and sending the IP and
port info w/ UDP to another computer (server) behind a firewall that then
connects to the client. This is all required because of quite draconian
firewalling rules (my machine is behind THREE different firewalls,
ouch!)]

ifconfig should be virtually the same everywhere, so parsing should be
something like this: (works on FreeBSD)
http://segment7.net/ruby-code/snippits/get_ip.rb


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Computers are like air conditioners. Both stop working, if you open windows.
– Adam Heath

Remember, UNIX is about processing text, don’t worry about all the messy
internals unless you need to :slight_smile:

···

Mauricio Fern?ndez (batsman.geo@yahoo.com) wrote:

On Mon, Jan 27, 2003 at 07:37:38AM +0900, Eric Hodel wrote:

ifconfig should be virtually the same everywhere, so parsing should be
something like this: (works on FreeBSD)
http://segment7.net/ruby-code/snippits/get_ip.rb

Great! I have been reading ifconfig’s (net-tools’s) sources, and
apparently that info is taken from /proc/net/ (under Linux at least) and
using ioctl, and I guess parsing is more portable than trying ioctl
magic…


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04