aru Posted January 14, 2003 Report Share Posted January 14, 2003 tobyink Frequent user Joined: 08 May 2002 Posts: 185 Location: London, England Post Posted: Sun Aug 04, 2002 7:44 pm Post subject: A third tip from Toby! _________________________________________________________________ Following on from my uptime2png script and my freaky dial-up settings, here's another useful/useless tip. I am connected to the Internet via a measely dial-up. Boo hoo. I used to be on broadband, and I will be again some day, but until then I have to cope with a connection that cuts itself off every 2 hours and when it reconnects has a totally different IP address! This of course makes it hard for remote users. What I needed was a way for remote users to be able to easily find my IP address. First of all, we create a Perl script that looks at ppp0 and determines your IP address: Code: #!/usr/bin/perl $IFCFG = '/sbin/ifconfig'; $GREP = '/bin/grep'; $line = `$IFCFG -v ppp0 | $GREP "inet addr"`; $line = substr($line, 20); ($line, @rest) = split(/ /, $line); print "$line"; Pretty easy eh? Now, as root, save this as /root/get_ppp0_ip.pl. And then chmod 700 ~/get_ppp0_ip.pl. Now open up /etc/ppp/ip-up.local. If it's empty, add this line at the top: Code: #!/bin/bash Now, at the end of the file, add these lines: Code: sleep 2 /root/get_ppp0_ip.pl -d > /YOUR_MACHINE_NAME.txt echo "" >> /YOUR_MACHINE_NAME.txt echo "Last Updated:" date >> /YOUR_MACHINE_NAME.txt sleep 2 Obviously, replacing the file name with the name of your computer. Below this, you'll need to add a command to upload /YOUR_MACHINE_NAME.txt to your remote web server (which we assume has a fixed IP!!!) As in my last tip, ncftpput is your friend here. I am lucky enough to have a server with SSH access which means that I can use scp instead: /bin/su tai -c "scp /ophelia.txt coach:public_html/" (Ophelia is the name of my machine, coach is my web server.) Make sure that you use keys/saved passwords etc so that the script can upload the file!!! arusabal Moderator Joined: 17 Apr 2002 Posts: 836 Location: Spain Post Posted: Sun Aug 04, 2002 10:50 pm Post subject: Re: A third tip from Toby! _________________________________________________________________ For those who doesn't know perl or have personal affairs against it, I suggest: Code: $ /sbin/ifconfig | grep P-t-P | awk '{print $2}' | awk -F ":" '{print $2}' Or better: Code: $ /sbin/ifconfig | awk '/P-t-P/ {print substr($2,6)}' DOlson Moderator Joined: 16 Apr 2002 Posts: 2393 Location: Canada Post Posted: Sun Aug 04, 2002 11:49 pm Post subject: _________________________________________________________________ I did this already using PHP. I thought that I posted it before... I guess not. Anyhow, here's the URL: http://mdkxp.by-a.com/rpm/ipupdate.tar.gz It works great, and it even allows you to upload it to an FTP server so someone can just view an html page to find your current IP. Editor's note: This thread was originally posted at the old MUB (Mandrake User Board at club-nihil). This post is the result of a 99% automatic backup, so due to its nature some text may be lost (improbable but possible). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.