#!/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 | |
by Anonymous Monk on Oct 30, 2000 at 23:19 UTC | |
|
RE: Slick way to upload dynamic IP addresses
by the_slycer (Chaplain) on Nov 01, 2000 at 02:10 UTC | |
|
RE: Slick way to upload dynamic IP addresses (non-Perlish comment)
by ybiC (Prior) on Oct 31, 2000 at 00:00 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |