This perl script can be used to upload IP addresses from a machine (windows, but easily enough linux, just change a few values) to a server via FTP. It's a quick and dirty fix, but it beats using other prefab programs... It runs in the background... It's my first USEFUL perl script, so don't be mean...
#!/usr/bin/perl -w #===================================================================== += # Author: Adam Bultman # Date: 27 October 2000 # Usage: This program runs a windows command (ipconfig), and pipes the + output # to a file. Once that is finished, it uploads the file to an f +tp # server. It then sleeps for 30 minutes, or a set time limit. +Then it # starts all over until interrupted. Swell! #===================================================================== +===== # Use the FTP module for Perl use Net::FTP; # Set some variables $time = 800; # Sleep for this many seconds $server = "server"; # Upload to this server $fileName = "file"; # Pipe to this file $userName = "userName"; # Set the user name... $password = "password"; # Terrible, but this is the password $cmd = "ipconfig |"; # Let's name the command #Let's assign an ftp connection... # Print out what the program does print "\nThis program will run \"ipconfig\" every $time seconds, pipe\ +n"; print "It to $fileName, and then upload the file to $server .\n"; for(;;) { # Open up the file and the command handle open (FILE, ">$fileName") || die "\nI couldn't open the file for o +verwriting. "; open (COMMAND, $cmd) || die "\nI couldn't run the program! "; # Try to print the results of the command to the file write_to_file; # Just for tying off loose ends close COMMAND || die " I couldn't close COMMAND "; close FILE || die " I couldn't close FILE"; $ftp = Net::FTP->new($server) || die "I couldn't open a connection + to $server "; # Log onto the server and put the file, then quit. $ftp->login($userName,$password); print "Logged in... "; $ftp->cwd('public_html'); print "Changed dir to public_html... "; $ftp->put($fileName); print "I put the file... "; $ftp->quit(); print "Logging out...\n"; print "I put the file $fileName to $server successfully.\n"; # Sleep the alloted time. $| = 1; sleep($time); } sub html_header { $document_title = $_[0]; print FILE "<HTTP_END"; print FILE "Content-type: text/html"; print FILE "<html>"; print FILE "<head>"; print FILE "<title>$document_title</title>"; print FILE "</head>"; print FILE "<body>"; print FILE "<center><h1>$document_title</h1></center>"; print FILE "<pre>"; } sub write_to_file { html_header("MY IP ADDRESS"); print FILE <COMMAND>; print FILE "</pre>"; print FILE "<hr>"; print FILE "</body>"; print FILE "</html>"; }

Replies are listed 'Best First'.
RE: Slick way to upload dynamic IP addresses
by dws (Chancellor) on Oct 30, 2000 at 02:25 UTC
    This approach has one significant shortcoming. If the PC is behind some NAT box (say, a corporate firewall or a LinkSys Broadband Router), then the IP address of the PC isn't particularly interesting to the outside world, since the outside world won't be able to connect to the PC using that IP address.

    I have DSL into a LinkSys router/hub, and have the DMZ host set to the local IP address of a Linux box. (Incoming socket connections get routed to the DMZ host, after the IP address gets translated from the router's externally visible IP address to the 192.168.1.* internal address specified for the DMZ host.)

    A cron job on the Linux box periodically makes an "I'm alive" HTTP request to a CGI on my ISP. The CGI captures REMOTE_ADDR, which is the externally visible IP address for the router (and the Linux box, since it's the DMZ host.)

    Invoking the same CGI with no parameters products a short page of HTML listing the last-known IP address for my home router/Linux box, along with a note about how recent the address is. I hit the CGI from work, open a secure shell connection to my home box, and can IRC from there.

      Remember: This isn't meant to be run from behind the NAT box. You are right: No one cares if the local machines IP is 192.168.0.1. all that matters is the outside IP address. So, you have it run _on_ your NAT box (like I do) and foreward any necessary packets into the internal network. I currently have windows 2000 forewarding SSH, SSH2, FTP, and Telnet requests(ports 22,22,21, and 23, respectively) to my linux box on the internal network. So I, like you, can do the same things. I can SSH, telnet, or FTP into my computers from far away. However, many people won't buy DSL Routers- they will have 486's routing packets running a light distro of linux- and then this comes in handy. Especially when you are likely to be disconnected frequently- as I am.
RE: Slick way to upload dynamic IP addresses
by the_slycer (Chaplain) on Nov 01, 2000 at 02:10 UTC
    I worked on something similar to this, there are some suggestions that I would make. First is to use the Sys::Hostname module and the Socket module to grab the ip, rather than pipe the output of ipconfig:
    use strict; use Sys::Hostname; use Socket; my $host = hostname(); my $ip = inet_ntoa(scalar(gethostbyname($host))); print $ip;
    This works as long as the host name is correct (at least on linux the hostname has to be proper - windows didn't really seem to matter).
    Second suggestion is obviously minor, but change the "public_html" to $htm_dir or something along those lines, not everybody uploads to public_html.
    Third and quite possibly most important use strict always. It is a big deal, it can save so much useless troubleshooting in the long run. I used to not - ever, but I have seen the wisdom, after spending a couple hours trying to find the bug in a largish script, finally realized that one of my variables was badly named. Use strict and -w and you will be happier in the future.

    Now for extra credit (grin) - rewrite this so that it changes one or many pre-existing web-pages, some people have a lot of links that point back to their home box from their isp's web page. And of course makes sure that it can pick up where it left off (ie, program hasn't been running for a few days for whatever reason, maybe IP has changed a couple of times since the last update). Fun fun. Cheers
RE: Slick way to upload dynamic IP addresses (non-Perlish comment)
by ybiC (Prior) on Oct 31, 2000 at 00:00 UTC
    Disclaimer:   this brief post doesn't even contain the word P*rl.

    I've done something similar, but placed snippet in Debian's /etc/ppp/ip-up.d/ so address-updating script is run only when connection is established.   Saves you the grief of waiting up to 1/2 hour after line drop.

    Dunno if Win32 RAS/DUN has anything similar, or if (Win or Linux) can do same for Ethernet-attached cablemodem/DSL router.
        cheers,
        Don
        striving for Perl Adept

A reply falls below the community's threshold of quality. You may see it by logging in.