Networking Forums

Networking Forums > Computer Networking > Linux Networking > Finding own ppp0 address

Reply
Thread Tools Display Modes

Finding own ppp0 address

 
 
Eduardo
Guest
Posts: n/a

 
      10-01-2003, 06:59 PM
How to find one's own interface IP address for sure? Short of sed'ing,
awk'ing, etc. the output of 'ifconfig ppp0', can't I just look into
/proc or somewhere else? Why not? or, How?
TIA
 
Reply With Quote
 
 
 
 
Lew Pitcher
Guest
Posts: n/a

 
      10-01-2003, 07:11 PM
Eduardo wrote:

> How to find one's own interface IP address for sure? Short of sed'ing,
> awk'ing, etc. the output of 'ifconfig ppp0', can't I just look into
> /proc or somewhere else? Why not? or, How?
> TIA


You /can/ add shell code to the /etc/ppp/ip-up and /etc/ppp/ip-down scripts
(or the ip-up.local & ip-down.local scripts if your distro uses them) to
record the IP address in a flat file; the IP address and interface names are
provided to both scripts as positional parameters ($1 is the interface name,
$4 is the IP address).

Here's how I do it:

In file /etc/ppp/ip-up
echo "$4" >/var/log/$1.ip


In file /etc/ppp/ip-down
rm -f /var/log/$1.ip


In a shell script of your own choosing...

if [ -f /var/log/ppp0.ip ] ;
then
echo PPP0 is UP, with IP address `cat /var/log/ppp0.ip`
fi


/etc/ppp/ip-up is run by pppd when it completes it's IP negotiation
and brings up a TCP/IP link. parameter #1 is the name of the interface
(ppp0, ppp1, etc.), and parameter #4 is the IP address assigned to the
local side of the connection. For the ppp0 interface, the 'echo'
command creates (or updates) the file /var/log/ppp0.ip with the IP
address assigned to it when the link comes active. Similarly, the
script would create/update /var/log/ppp1.ip for the IP address
assigned to ppp1 when _that_ interface comes up

/etc/ppp/ip-down is run by pppd when it disconnects the IP support
from an interface and brings down the TCP/IP link. Again, parameter #1
is the name of the interface and parameter #4 is the IP address that
had been assigned to the local side of that connection. The 'rm -f'
deletes the /var/log/ppp0.ip (or /var/log/ppp1.ip, etc.) file when
that IP link comes down.

Finally, the shell script test looks for the existance of the
/var/log/ppp0.ip file, and dumps it's contents. If the file exists, we
can be sure that the /etc/ppp/ip-up script has run (as a result of the
link coming up), and the /etc/ppp/ip-down script has not run, meaning
that the link is up. If the file doesn't exist, it is because the
/etc/ppp/ip-down script deleted it when the link came down. Thus, the
existance of the file is an indicator of the state of the link.

Additionally, the contents of the file provides some value. When the
link is up, programmers sometimes have a need to establish the local
IP address of the link. The usual route is to grep the output of
ifconfig for the IP address in the ppp0 adaptor description, but this
is not very usefull in some dial-on-demand configs which assign a
dummy IP address to the adaptor when it is disconnected from the net.
However, since the /var/log/ppp0.ip file indicates (by it's existance)
the presence of a valid link, the contents of the file can be used to
determine the IP address assigned to the link.

--

Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)

 
Reply With Quote
 
Walter Schiessberg
Guest
Posts: n/a

 
      10-01-2003, 07:23 PM
Eduardo wrote on 01.10.2003 20:59:

> How to find one's own interface IP address for sure? Short of sed'ing,
> awk'ing, etc. the output of 'ifconfig ppp0', can't I just look into
> /proc or somewhere else? Why not? or, How?


Simple as that:
ifconfig ppp0 | awk '/inet/, gsub(":", " ") { print $3 }'

--
Walter

 
Reply With Quote
 
Douglas Clinton
Guest
Posts: n/a

 
      10-01-2003, 07:57 PM
On Wed, 01 Oct 2003 11:59:39 -0700, Eduardo wrote:

> How to find one's own interface IP address for sure? Short of sed'ing,
> awk'ing, etc. the output of 'ifconfig ppp0', can't I just look into /proc
> or somewhere else? Why not? or, How? TIA


Here is a perl script to get your WAN IP address. The one assigned by
your ISP.

--------------------
#!/usr/bin/perl
# This is a perl version of Robin Keir's IP2 at http://keir.net/ip2.html
# it gets your Wan IP address and provate IP address if you have one
#
# This script is for GNU/linux and BSD if you are running windows, use Robin Keir's
# program at the site above.
#
# This script will print out your WAN address and name as seen from a host outside
# your internal network
# This is useful for those behind a NAT router and need to know the Internet view of
# your host, useful for various filesharing apps and IRC stuff
#
# The following is a list of servers you can use/try if you need to substitute
# the default ecerami.com address
#
# http://ecerami.com/servlet/coreservl...owCGIVariables
# http://www.sanford.com/introcgi/cgi-...e.pl?something
# http://www.mueloliva.es/cgi-bin/variables.cgi?'0024'
# http://inetarena.com/cgi-bin/environment.pl?this=that
# http://curry.edschool.virginia.edu/g.../cgi-test.html
# http://www.cfhub.com/examples/cgi/
#
# This script was created by Douglas Clinton (E-Mail Removed)
# It is disrtibuted inder the GNU GPL if it doesnt work send me an email
# If you think that this script has damaged your computer get a brain scan...it can't
#
# Douglas Clinton


use LWP::Simple;

# First lets get the info we need from our favorite site
@url=get("http://ecerami.com/servlet/coreservlets.ShowCGIVariables");


# This section Finds the match for the WAN IP
foreach $i (@url) {
if ($i =~ /(\d+)(\.\d+){3}/) {
@stuff = $i;
#print "$i";
$string = $i;
$string =~ s/<([^>]|\n)*>//g ; # removes html tags
@stuff = $string;
#print "\n$string";
}
}

@words = split " ", $string;


$raw_addr = $words[13];
$raw_name = $words[14];

$clean_addr = substr($raw_addr, 11, 13);
# this next line prints the your WAN address
print "$clean_addr\n";


$clean_name = substr($raw_name, 11, 45);
# this nest line prints your WAN name
print "$clean_name\n";

--------
THE END
---------

Good Luck



--
GNU/Linux is God
get used to it
(E-Mail Removed)
Linux User # 276385

 
Reply With Quote
 
Alan Connor
Guest
Posts: n/a

 
      10-01-2003, 09:59 PM
On 1 Oct 2003 11:59:39 -0700, Eduardo <(E-Mail Removed)> wrote:
>
>
> How to find one's own interface IP address for sure? Short of sed'ing,
> awk'ing, etc. the output of 'ifconfig ppp0', can't I just look into
> /proc or somewhere else? Why not? or, How?
> TIA


That perl script seem a little like overkill for the job?

Take a look at /var/log/syslog (or perhaps the appriate log has a somewhat
different name on your distro...I'm running Debian) with a tail -100
and you'll see lines like this towards the end:

Oct 1 14:30:43 xxxxxx pppd[11794]: local IP address 63.xxx.xxx.xxx
Oct 1 14:30:43 xxxxxx pppd[11794]: remote IP address 63.xxx.xxx.xxx

(IP addresses and hostname altered above)

The first address is my present IP on the ppp0 interface and the second is
the present address of my ISP at the other end of the modem connection.

It is a simple matter to grep these out. Just put a function like this
in your .bashrc:

ga () {

grep 'local *IP' /var/log/syslog | tail -1 ;

}

That greps out all the lines with that regex in them, then displays the
last one, which would have your current IP address in it, as well as that
other useful informaion. If you want to get fancy, then:

ga () {

jj=`tail -1 /var/log/syslog | grep i'local *IP | sed -n 's/\(^.*address\
*\) \(.*$\)/\2/p'`
clear;
echo; echo; echo;
echo "Your Current IP Address is : $jj" ;
echo; echo; echo;

}


Now enter source .bashrc, and whenever you want to see your present local
IP, just enter ga.

--
Later, Alan C
You can find my email address at the website: contact.html
take control of your mailbox ----- elrav1 ----- http://tinyurl.com/l55a
 
Reply With Quote
 
Walter Schiessberg
Guest
Posts: n/a

 
      10-01-2003, 11:55 PM
Alan Connor wrote on 01.10.2003 23:59:


> On 1 Oct 2003 11:59:39 -0700, Eduardo <(E-Mail Removed)> wrote:
>
>>
>>How to find one's own interface IP address for sure? Short of sed'ing,
>>awk'ing, etc. the output of 'ifconfig ppp0', can't I just look into
>>/proc or somewhere else? Why not? or, How?
>>TIA

>
>
> That perl script seem a little like overkill for the job?


Definitly
What do we need ecerami.com for if we only need an IP?

[...]
> It is a simple matter to grep these out. Just put a function like this
> in your .bashrc:
>
> ga () {
>
> grep 'local *IP' /var/log/syslog | tail -1 ;
>
> }
>
> That greps out all the lines with that regex in them, then displays the
> last one, which would have your current IP address in it, as well as that
> other useful informaion. If you want to get fancy, then:
>
> ga () {
>
> jj=`tail -1 /var/log/syslog | grep i'local *IP | sed -n 's/\(^.*address\
> *\) \(.*$\)/\2/p'`


Strange. Works neither in bash nor sh.
What if the entry is just a line above?
I'd prefer awk again:
awk '/local *IP/ {print $NF}' /var/log/syslog | tail -1

> clear;
> echo; echo; echo;
> echo "Your Current IP Address is : $jj" ;
> echo; echo; echo;
>
> }
>
>
> Now enter source .bashrc, and whenever you want to see your present local
> IP, just enter ga.
>


Fails if /var/log/syslog|messages is only readable by root like in many
Linux flavours.
And what if the log file is just rotated?
So instead of worrying about access rights or changing default system
scripts (I have my additions in ip-up.local) it might be the easy way to
get the information from ifconfig.


--
Walter

 
Reply With Quote
 
Alan Connor
Guest
Posts: n/a

 
      10-02-2003, 12:30 AM
On Thu, 02 Oct 2003 01:55:12 +0200, Walter Schiessberg <(E-Mail Removed)> wrote:
>
>
> Alan Connor wrote on 01.10.2003 23:59:
>
>
>> On 1 Oct 2003 11:59:39 -0700, Eduardo <(E-Mail Removed)> wrote:
>>
>>>
>>>How to find one's own interface IP address for sure? Short of sed'ing,
>>>awk'ing, etc. the output of 'ifconfig ppp0', can't I just look into
>>>/proc or somewhere else? Why not? or, How?
>>>TIA

>>
>>
>> That perl script seem a little like overkill for the job?

>
> Definitly
> What do we need ecerami.com for if we only need an IP?
>
> [...]
>> It is a simple matter to grep these out. Just put a function like this
>> in your .bashrc:
>>
>> ga () {
>>
>> grep 'local *IP' /var/log/syslog | tail -1 ;
>>
>> }
>>
>> That greps out all the lines with that regex in them, then displays the
>> last one, which would have your current IP address in it, as well as that
>> other useful informaion. If you want to get fancy, then:
>>
>> ga () {
>>
>> jj=`tail -1 /var/log/syslog | grep i'local *IP | sed -n 's/\(^.*address\
>> *\) \(.*$\)/\2/p'`

>
> Strange. Works neither in bash nor sh.


The first on does, but I screwed up the second one.

it should read jj=`grep 'local *IP' /var/log/syslog | ....

will work in bash and I'm pretty sure the syntax for a shell function
is the same in sh.

But this is dependent on that being the log the information appears in
and that being the wording of the entry, both of which could be somewhat
different on various distros and releases. Same for any awk script.


> What if the entry is just a line above?
> I'd prefer awk again:
> awk '/local *IP/ {print $NF}' /var/log/syslog | tail -1
>
>> clear;
>> echo; echo; echo;
>> echo "Your Current IP Address is : $jj" ;
>> echo; echo; echo;
>>
>> }
>>
>>
>> Now enter source .bashrc, and whenever you want to see your present local
>> IP, just enter ga.
>>

>
> Fails if /var/log/syslog|messages is only readable by root like in many
> Linux flavours.


So? Grep the info from somewhere else

> And what if the log file is just rotated?
> So instead of worrying about access rights or changing default system
> scripts (I have my additions in ip-up.local) it might be the easy way to
> get the information from ifconfig.
>
>
> --
> Walter
>


Why not? Just as easy as anyplace else.

/sbin/ifconfig -a ppp0

--
Later, Alan C
You can find my email address at the website: contact.html
take control of your mailbox ----- elrav1 ----- http://tinyurl.com/l55a
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding MAC address of currently connected AP Rick Onanian Wireless Internet 23 01-24-2008 04:51 PM
Finding IP address of new router GoBruins Wireless Internet 9 09-04-2006 11:31 PM
Finding out email address? Blair Broadband 9 11-12-2005 04:43 AM
finding ip address Sam Windows Networking 2 05-18-2004 04:53 AM
Finding the ip address your really using. T Home Networking 5 08-06-2003 08:11 AM



1 2 3 4 5 6 7 8 9 10 11