Skip to contentSkip to conversation

grep for ip address on boot

DISCUSSION Bryan Simmons 3 participants 3 messages Nov 19, 2002

lore
Share & tools
lore
#0 lore raw

I have an adsl connection that uses a dynamic IP from my ISP. I use the adsl-status script to find out what my IP is at any time. What I want to do is parse the response I get from adsl-status to isolate my IP. Here is the output of the adsl-status script:

adsl-status: Link is up and running on interface ppp0
ppp0 Link encap:Point-to-Point Protocol
inet addr:151.196.10.63 P-t-P:10.4.25.1 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1 RX packets:1962 errors:0 dropped:0 overruns:0 frame:0 TX packets:1987 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:3
RX bytes:1600510 (1.5 Mb) TX bytes:362634 (354.1 Kb)

I figured that by using this command: adsl-status | grep -o addr:['0'-'9']

Or some combination thereof, I would be able to get the full IP isolated. I realize that the problem is that an IP can have from 1-3 digits between each dot, and this screws up my regexp. Can anyone suggest a web site or some sort of regexp that better suits this pursuit?

The purpose of this is to parse out my IP address and write it into a 'header(Location:http://)' command in an index.php script that will be automatically ftp'd to another web server to simulate a bound domain name for my dynamic IP web site. I got the site and the redirect working, I just want the site to be able to remain up if there is an unattended reboot. Obviously I will put all necessary scripting in an init file to handle the IP parsing and ftp to allow the site to remain accessible to all.

Thanks guys!

Signature · 15 lines
Regards,

Bryan Simmons

=-=-=-=-==-=-=-=-==-=-=-=-==-=-=-=-=-=
 "More hay Trigger?", "No thanks Roy,
  I'm stuffed."
=-=-=-=-==-=-=-=-==-=-=-=-==-=-=-=-=-=
http://www.sarcastic-bastard.com

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
#1 lore raw
Quoted 14 lines · Bryan Simmons

I have an adsl connection that uses a dynamic IP from my ISP. I use the adsl-status script to find out what my IP is at any time. What I want to do is parse the response I get from adsl-status to isolate my IP. Here is the output of the adsl-status script:

adsl-status: Link is up and running on interface ppp0
ppp0 Link encap:Point-to-Point Protocol
inet addr:151.196.10.63 P-t-P:10.4.25.1 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1 RX packets:1962 errors:0 dropped:0 overruns:0 frame:0 TX packets:1987 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:3
RX bytes:1600510 (1.5 Mb) TX bytes:362634 (354.1 Kb)

Quoted 2 lines

I figured that by using this command: adsl-status | grep -o addr:['0'-'9']

adsl-status | grep inet | awk '{print $2}' | awk -F\: '{print $2}'

This grep's for the inet addr line. Then awk takes word #2. Then tells awk that : is the seperator instead of space, and take word #2 again.

This _should_ work, it worked with ifconfig ppp0 here, which is what that adsl-status seems to be calling.

Mike

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#2 lore raw
In reply to Bryan Simmons

I don't know how promptly your application requires you to sync with ppp0 IP address changes, but there is an off-the-shelf alternative to what you are proposing. When pppd runs, it will execute the script /etc/ppp/ip-up, and that script has access to the local IP address as an environment variable (IPLOCAL). This gets used, for example, as a way to update a firewall (ipchains or iptables) when the interface address changes (as it will from time to time with PPPoE over ADSL, which I assume is what you have). It might do what you want a bit more easily than the approach you are trying for.

Quoted 4 lines · Bryan Simmons

I have an adsl connection that uses a dynamic IP from my ISP. I use the adsl-status script to find out what my IP is at any time. What I want to do is parse the response I get from adsl-status to isolate my IP. Here is the output of the adsl-status script:

[details deleted]

--
-------------------------------------------"Never tell me the odds!"--------
Ray Olszewski -- Han Solo
Palo Alto, California, USA [email protected]
-------------------------------------------------------------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs